GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — :wrench: finalize cli options · nullstack/nullstack@c1d09a2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • scripts
    • index.js
  • server
    • server.js
  • tests
    • package.json
  • webpack.config.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎scripts/index.js‎

Copy file name to clipboardExpand all lines: scripts/index.js
+20-7Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { version } = require('../package.json');
44

55
const webpack = require('webpack');
66
const path = require('path');
7-
const { existsSync } = require('fs');
7+
const { existsSync, rmdirSync, readdir, unlink } = require('fs');
88
const customConfig = path.resolve(process.cwd(), './webpack.config.js');
99
const config = existsSync(customConfig) ? require(customConfig) : require('../webpack.config');
1010
const dotenv = require('dotenv')
@@ -48,7 +48,7 @@ function getPort(port) {
4848
return port || process.env['NULLSTACK_SERVER_PORT'] || process.env['PORT'] || 3000
4949
}
5050

51-
async function start({ input, port, env, mode = 'spa', hot }) {
51+
async function start({ input, port, env, mode = 'spa', cold, disk }) {
5252
const environment = 'development'
5353
console.log(` 🚀️ Starting your application in ${environment} mode...`);
5454
loadEnv(env)
@@ -60,18 +60,20 @@ async function start({ input, port, env, mode = 'spa', hot }) {
6060
const ports = await getFreePorts()
6161
process.env['NULSTACK_SERVER_PORT_YOU_SHOULD_NOT_CARE_ABOUT'] = ports[0]
6262
process.env['NULSTACK_SERVER_SOCKET_PORT_YOU_SHOULD_NOT_CARE_ABOUT'] = ports[1]
63-
process.env['NULLSTACK_ENVIRONMENT_HOT'] = (!!hot).toString()
63+
process.env['NULLSTACK_ENVIRONMENT_HOT'] = (!cold).toString()
64+
process.env['NULLSTACK_ENVIRONMENT_DISK'] = (!!disk).toString()
6465
if (!process.env['NULLSTACK_PROJECT_DOMAIN']) process.env['NULLSTACK_PROJECT_DOMAIN'] = 'localhost'
6566
if (!process.env['NULLSTACK_WORKER_PROTOCOL']) process.env['NULLSTACK_WORKER_PROTOCOL'] = 'http'
6667
const target = `${process.env['NULLSTACK_WORKER_PROTOCOL']}://${process.env['NULLSTACK_PROJECT_DOMAIN']}:${process.env['NULSTACK_SERVER_PORT_YOU_SHOULD_NOT_CARE_ABOUT']}`
68+
const writeToDisk = disk ? true : (path) => path.includes('server')
6769
const devServerOptions = {
6870
hot: 'only',
6971
open: false,
7072
host: process.env['NULLSTACK_PROJECT_DOMAIN'],
7173
devMiddleware: {
7274
index: false,
7375
stats: 'none',
74-
writeToDisk: true,
76+
writeToDisk,
7577
},
7678
client: {
7779
overlay: { errors: true, warnings: false },
@@ -120,8 +122,18 @@ async function start({ input, port, env, mode = 'spa', hot }) {
120122
webSocketServer: require.resolve('./socket'),
121123
port: process.env['NULLSTACK_SERVER_PORT']
122124
};
123-
const clientCompiler = getCompiler({ environment, input });
124-
const server = new WebpackDevServer(devServerOptions, clientCompiler);
125+
const compiler = getCompiler({ environment, input, disk });
126+
const outputPath = compiler.compilers[0].outputPath;
127+
readdir(outputPath, (err, files) => {
128+
if (err) throw err;
129+
for (const file of files) {
130+
if (file === '.cache') continue;
131+
unlink(path.join(outputPath, file), err => {
132+
if (err) throw err;
133+
});
134+
}
135+
});
136+
const server = new WebpackDevServer(devServerOptions, compiler);
125137
const portChecker = require('express')().listen(process.env['NULLSTACK_SERVER_PORT'], () => {
126138
portChecker.close()
127139
server.startCallback(() => {
@@ -155,7 +167,8 @@ program
155167
.option('-p, --port <port>', 'Port number to run the server')
156168
.option('-i, --input <input>', 'Path to project that will be started')
157169
.option('-e, --env <name>', 'Name of the environment file that should be loaded')
158-
.option('--hot', 'Enable hot module replacement')
170+
.option('-d, --disk', 'Write files to disk')
171+
.option('-c, --cold', 'Disable hot module replacement')
159172
.helpOption('-h, --help', 'Learn more about this command')
160173
.action(start)
161174

Collapse file

‎server/server.js‎

Copy file name to clipboardExpand all lines: server/server.js
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,11 @@ server.start = function () {
222222

223223
server.listen(server.port, async () => {
224224
if (environment.development) {
225-
const content = await server.prerender('/');
226-
const target = process.cwd() + `/.development/index.html`
227-
writeFileSync(target, content)
225+
if (process.env['NULLSTACK_ENVIRONMENT_DISK'] === 'true') {
226+
const content = await server.prerender('/');
227+
const target = process.cwd() + `/.development/index.html`
228+
writeFileSync(target, content)
229+
}
228230
const socket = new WebSocket(`ws://localhost:${process.env['NULLSTACK_SERVER_PORT']}/ws`);
229231
socket.onopen = async function (e) {
230232
socket.send('{"type":"NULLSTACK_SERVER_STARTED"}')
Collapse file

‎tests/package.json‎

Copy file name to clipboardExpand all lines: tests/package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"purgecss-webpack-plugin": "^4.1.3"
1414
},
1515
"scripts": {
16-
"start": "npx nullstack start --input=./tests --port=6969 --env=test --mode=spa --hot",
16+
"start": "npx nullstack start --input=./tests --port=6969 --env=test --mode=spa",
1717
"build": "npx nullstack build --input=./tests --env=test",
1818
"test": "npm run build && jest --runInBand",
1919
"script": "node src/scripts/run.js"
Collapse file

‎webpack.config.js‎

Copy file name to clipboardExpand all lines: webpack.config.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ function server(env, argv) {
244244
}
245245

246246
function client(env, argv) {
247+
const disk = !!argv.disk
247248
const dir = argv.input ? path.join(__dirname, argv.input) : process.cwd();
248249
const isDev = argv.environment === 'development';
249250
const folder = isDev ? '.development' : '.production';
@@ -255,7 +256,7 @@ function client(env, argv) {
255256
chunkFilename: '[chunkhash].client.css'
256257
}),
257258
]
258-
if (isDev) {
259+
if (disk) {
259260
plugins.push(new CopyPlugin({
260261
patterns: [
261262
{ from: "public", to: "../.development" },

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.