GeezerVison is showing github.com — :sparkles: optional start modes · nullstack/nullstack@661916c
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: scripts/index.js +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,7 +27,7 @@ function getClientCompiler(options) { | 27 | 27 | return webpack(getConfig(options)[1]) | 28 | 28 | } | 29 | 29 |
| 30 | | -async function start({ input, port, env }) { | | 30 | +async function start({ input, port, env, mode = 'ssr', hot }) { | 31 | 31 | const environment = 'development'; | 32 | 32 | const serverCompiler = getServerCompiler({ environment, input }); | 33 | 33 | let clientStarted = false | @@ -37,7 +37,7 @@ async function start({ input, port, env }) { | 37 | 37 | } | 38 | 38 | dotenv.config({ path: envPath }) | 39 | 39 | port ??= process.env['NULLSTACK_SERVER_PORT'] || process.env['PORT'] || 3000 | 40 | | - process.env['NULLSTACK_ENVIRONMENT_MODE'] = 'spa' | | 40 | + process.env['NULLSTACK_ENVIRONMENT_MODE'] = mode | 41 | 41 | console.log(` 🚀️ Starting your application in ${environment} mode...`); | 42 | 42 | const WebpackDevServer = require('webpack-dev-server'); | 43 | 43 | const { setLogLevel } = require('webpack/hot/log') | @@ -53,7 +53,7 @@ async function start({ input, port, env }) { | 53 | 53 | if (!clientStarted) { | 54 | 54 | clientStarted = true | 55 | 55 | const devServerOptions = { | 56 | | - hot: true, | | 56 | + hot: !!hot, | 57 | 57 | open: false, | 58 | 58 | devMiddleware: { | 59 | 59 | index: false | @@ -114,18 +114,20 @@ program | 114 | 114 | .command('start') | 115 | 115 | .alias('s') | 116 | 116 | .description('Start application in development environment') | | 117 | + .addOption(new program.Option('-m, --mode <mode>', 'Build production bundles').choices(['ssr', 'spa'])) | 117 | 118 | .option('-p, --port <port>', 'Port number to run the server') | 118 | 119 | .option('-i, --input <input>', 'Path to project that will be started') | 119 | 120 | .option('-o, --output <output>', 'Path to build output folder') | 120 | 121 | .option('-e, --env <name>', 'Name of the environment file that should be loaded') | | 122 | + .option('--hot', 'Enable hot module replacement') | 121 | 123 | .helpOption('-h, --help', 'Learn more about this command') | 122 | 124 | .action(start) | 123 | 125 |
| 124 | 126 | program | 125 | 127 | .command('build') | 126 | 128 | .alias('b') | 127 | 129 | .description('Build application for production environment') | 128 | | - .addOption(new program.Option('-m, --mode <mode>', 'Build production bundles').choices(buildModes)) | | 130 | + .addOption(new program.Option('-m, --mode <mode>', 'Build production bundles').choices(['ssr', 'spa', 'ssg'])) | 129 | 131 | .option('-i, --input <input>', 'Path to project that will be built') | 130 | 132 | .option('-o, --output <output>', 'Path to build output folder') | 131 | 133 | .option('-c, --cache', 'Cache build results in .production folder') | |
Collapse file Copy file name to clipboardExpand all lines: server/prerender.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -36,7 +36,7 @@ export async function prerender(request, response) { | 36 | 36 | scope.plugins = loadPlugins(scope); | 37 | 37 |
| 38 | 38 | try { | 39 | | - if (environment.production) { | | 39 | + if (environment.production || environment.mode !== 'spa') { | 40 | 40 | const tree = await generateTree(generator.starter(), scope); | 41 | 41 | scope.body = render(tree, scope); | 42 | 42 | } | |
Collapse file Copy file name to clipboardExpand all lines: tests/package.json +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 13 | 13 | "purgecss-webpack-plugin": "^4.1.3" | 14 | 14 | }, | 15 | 15 | "scripts": { | 16 | | - "start": "npx nullstack start --input=./tests --port=6969 --env=test", | 17 | | - "build": "npx nullstack build --input=./tests --mode=ssr --env=test", | | 16 | + "start": "npx nullstack start --input=./tests --port=6969 --env=test --mode=spa --hot", | | 17 | + "build": "npx nullstack build --input=./tests --env=test", | 18 | 18 | "test": "npm run build && jest", | 19 | 19 | "script": "node src/scripts/run.js" | 20 | 20 | } | 21 | | -} | | 21 | +} |
|