Skip to content

Commit

Permalink
refactor: [skip ci] Separate internal concepts of config and env
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Aug 13, 2022
1 parent 29da589 commit 12a3ef0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
3 changes: 1 addition & 2 deletions packages/cli/lib/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ async function command(src, argv) {
argv.src = src || argv.src;
// add `default:true`s, `--no-*` disables
argv.prerender = toBool(argv.prerender);
argv.production = toBool(argv.production);

let cwd = resolve(argv.cwd);

Expand All @@ -99,7 +98,7 @@ async function command(src, argv) {
await promisify(rimraf)(dest);
}

let stats = await runWebpack(argv, false);
let stats = await runWebpack(argv, true);

if (argv.json) {
await runWebpack.writeJsonStats(cwd, stats);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/commands/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async function command(src, argv) {
}
}

return runWebpack(argv, true);
return runWebpack(argv, false);
}

async function determinePort(port) {
Expand Down
24 changes: 13 additions & 11 deletions packages/cli/lib/lib/webpack/run-webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function devBuild(env) {
});
}

async function prodBuild(env) {
async function prodBuild(config, env) {
env = { ...env, isServer: false, dev: !env.production, ssr: false };
let config = await clientConfig(env);
await transformConfig(env, config);
Expand Down Expand Up @@ -220,20 +220,22 @@ function stripLoaderFromModuleNames(m) {
return m;
}

module.exports = function (env, watch = false) {
env.isProd = env.production; // shorthand
env.isWatch = !!watch; // use HMR?
env.cwd = resolve(env.cwd || process.cwd());
module.exports = function (argv, isProd) {
const env = {
isProd,
isWatch: !isProd,
}
const config = argv;
config.cwd = resolve(argv.cwd || process.cwd());

// env.src='src' via `build` default
let src = resolve(env.cwd, env.src);
env.src = isDir(src) ? src : env.cwd;
// config.src='src' via `build` default
const src = resolve(config.cwd, argv.src);
config.src = isDir(src) ? src : config.cwd;

// attach sourcing helper
env.source = dir => resolve(env.src, dir);
config.source = dir => resolve(config.src, dir);

// determine build-type to run
return (watch ? devBuild : prodBuild)(env);
return (isProd ? prodBuild : devBuild)(config, env)
};

module.exports.writeJsonStats = writeJsonStats;

0 comments on commit 12a3ef0

Please sign in to comment.