Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions lib/groups/AdvancedGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,39 @@ class AdvancedGroup extends GroupHelper {
// }
// }
resolveOptions() {
const { args } = this;
const {
args,
opts: { options },
} = this;

if (args.hot) {
const { HotModuleReplacementPlugin } = require('webpack');
const hotModuleVal = new HotModuleReplacementPlugin();
if (this.opts.options && this.opts.options.plugins) {
this.opts.options.plugins.unshift(hotModuleVal);
if (options && options.plugins) {
options.plugins.unshift(hotModuleVal);
} else {
this.opts.options.plugins = [hotModuleVal];
options.plugins = [hotModuleVal];
}
}
if (args.prefetch) {
const { PrefetchPlugin } = require('webpack');
const prefetchVal = new PrefetchPlugin(null, args.prefetch);
if (this.opts.options && this.opts.options.plugins) {
this.opts.options.plugins.unshift(prefetchVal);
if (options && options.plugins) {
options.plugins.unshift(prefetchVal);
} else {
this.opts.options.plugins = [prefetchVal];
// Currently the Plugin function is not functional -> https://github.com/webpack/webpack-cli/pull/1140#discussion_r376761359
// options.plugins = [prefetchVal];
}
}
if (args.plugin) {
if (this.opts.options && this.opts.options.plugins) {
this.opts.options.plugins.unshift(this.loadPlugin(args.plugin));
if (options && options.plugins) {
options.plugins.unshift(this.loadPlugin(args.plugin));
} else {
this.opts.options.plugins = [this.loadPlugin(args.plugin)];
options.plugins = [this.loadPlugin(args.plugin)];
}
}
if (args.target) {
this.opts.options.target = args.target;
options.target = args.target;
}

if (args.global) {
Expand Down Expand Up @@ -119,10 +124,10 @@ class AdvancedGroup extends GroupHelper {

const { ProvidePlugin } = require('webpack');
const globalVal = new ProvidePlugin(providePluginObject);
if (this.opts.options && this.opts.options.plugins) {
this.opts.options.plugins.unshift(globalVal);
if (options && options.plugins) {
options.plugins.unshift(globalVal);
} else {
this.opts.options.plugins = [globalVal];
options.plugins = [globalVal];
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions lib/groups/BasicGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,26 @@ class BasicGroup extends GroupHelper {
}
resolveFlags() {
const { args } = this;
const { outputOptions, options } = this.opts;
Object.keys(args).forEach(arg => {
if (this.WEBPACK_OPTION_FLAGS.includes(arg)) {
this.opts.outputOptions[arg] = args[arg];
outputOptions[arg] = args[arg];
}
// TODO: to add once webpack bundle analyzer is installed, which is not at the moment
// if (arg == 'analyze') {
// const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
// this.opts.options.plugins = [new BundleAnalyzerPlugin()];
// }
if (arg === 'sourcemap') {
this.opts.options.devtool = args[arg] || 'eval';
this.opts.outputOptions.devtool = args[arg];
options.devtool = args[arg] || 'eval';
outputOptions.devtool = args[arg];
}
if (arg === 'entry') {
this.opts.options[arg] = this.resolveFilePath(args[arg], 'index.js');
options[arg] = this.resolveFilePath(args[arg], 'index.js');
}
});
if (this.opts.outputOptions['dev']) {
this.opts.outputOptions['prod'] = undefined;
if (outputOptions['dev']) {
outputOptions['prod'] = undefined;
}
}

Expand Down
12 changes: 6 additions & 6 deletions lib/utils/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ class Compiler {
});

if (outputOptions.infoVerbosity === 'verbose') {
const resolveCompilationName = compilation => {
return compilation.name ? compilation.name : '';
};
if (outputOptions.watch) {
compilation.hooks.watchRun.tap('WebpackInfo', compilation => {
const compilationName = compilation.name ? compilation.name : '';
logger.info('Compilation ' + compilationName + ' starting…');
logger.info(`Compilation ${resolveCompilationName(compilation)} starting…`);
});
} else {
compilation.hooks.beforeRun.tap('WebpackInfo', compilation => {
const compilationName = compilation.name ? compilation.name : '';
logger.info('Compilation ' + compilationName + ' starting…');
logger.info(`Compilation ${resolveCompilationName(compilation)} starting…`);
});
}
compilation.hooks.done.tap('WebpackInfo', compilation => {
const compilationName = compilation.name ? compilation.name : '';
logger.info('Compilation ' + compilationName + ' finished');
logger.info(`Compilation ${resolveCompilationName(compilation)} finished`);
});
}
}
Expand Down
19 changes: 13 additions & 6 deletions lib/utils/interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,19 @@ module.exports = async function(config, outputOptions, processingMessageBuffer)
if (isExitCtrl(key)) {
console.clear();
process.exit();
} else if (key.name === 'down') {
process.stdout.write(ansiEscapes.cursorNextLine);
} else if (key.name === 'up') {
process.stdout.write(ansiEscapes.cursorPrevLine);
} else if (key.name === 'return') {
// TODO: get line and do stuff
}
switch (key.name) {
case 'down':
process.stdout.write(ansiEscapes.cursorNextLine);
break;
case 'up':
process.stdout.write(ansiEscapes.cursorPrevLine);
break;
case 'return':
// TODO: get line and do stuff
break;
default:
break;
}
});

Expand Down
6 changes: 3 additions & 3 deletions lib/utils/zero-config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function getEnvFromOptionsAndMode(mode, optionsObject) {
const { dev, prod } = optionsObject;

if ((process.env.NODE_ENV && process.env.NODE_ENV === 'production') || process.env.NODE_ENV === 'development') {
return process.env.NODE_ENV;
const NODE_ENV = process.env.NODE_ENV;
if (NODE_ENV && (NODE_ENV === 'production' || NODE_ENV === 'development')) {
return NODE_ENV;
} else if (prod) {
return 'production';
} else if (dev) {
Expand Down