Skip to content

Commit 1a467b6

Browse files
committed
feat: better defaults, cleanup
1 parent 080c44c commit 1a467b6

5 files changed

Lines changed: 24 additions & 12 deletions

File tree

lib/utils/compiler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function getCompiler(opts) {
176176
return webpack(opts.options);
177177
}
178178

179-
async function webpackInstance(opts, shouldUseMem) {
179+
async function webpackInstance(opts) {
180180
const { outputOptions, processingErrors, options } = opts;
181181

182182
if (processingErrors.length > 0) {
@@ -194,7 +194,7 @@ async function webpackInstance(opts, shouldUseMem) {
194194

195195
if (outputOptions.interactive) {
196196
const interactive = require('./interactive');
197-
return interactive(options, outputOptions, processingErrors, shouldUseMem);
197+
return interactive(options, outputOptions, processingErrors);
198198
}
199199
if (compiler.compilers) {
200200
compiler.compilers.forEach((comp, idx) => {

lib/utils/development-config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
const { join, resolve } = require('path');
12
const TerserPlugin = require('terser-webpack-plugin');
23
const JsConfigWebpackPlugin = require('js-config-webpack-plugin');
34

5+
const defaultOutputPath = resolve(join(process.cwd(), 'dist'));
6+
47
module.exports = {
58
mode: 'development',
69
entry: './index.js',
10+
output: {
11+
path: defaultOutputPath,
12+
filename: 'bundle.js'
13+
},
714
plugins: [new JsConfigWebpackPlugin()],
815

916
optimization: {

lib/utils/interactive.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ const ENTER_KEY = '\n';
102102
const B_KEY = 'b';
103103
const C_KEY = 'c';
104104

105-
module.exports = async function(config, outputOptions, processingErrors, shouldUsemem) {
105+
module.exports = async function(config, outputOptions, processingErrors) {
106106
const stdin = process.stdin;
107107
stdin.setEncoding('utf-8');
108108
stdin.setRawMode(true);
109109
readline.emitKeypressEvents(stdin);
110110

111111
outputOptions.interactive = false;
112112

113-
const webpackCompilation = await webpack({ options: config, outputOptions, processingErrors }, shouldUsemem);
113+
const webpackCompilation = await webpack({ options: config, outputOptions, processingErrors });
114114
/* if(errors) {
115115
Hngggg
116116
} */
@@ -163,7 +163,7 @@ module.exports = async function(config, outputOptions, processingErrors, shouldU
163163
if (state.length) {
164164
state.pop();
165165
}
166-
const webpackCompilation = await webpack({ options: config, outputOptions, processingErrors }, shouldUsemem);
166+
const webpackCompilation = await webpack({ options: config, outputOptions, processingErrors });
167167
state.push(webpackCompilation);
168168
informActions();
169169
isSub = true;

lib/utils/production-config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
const { join, resolve } = require('path');
12
const TerserPlugin = require('terser-webpack-plugin');
23
const JsConfigWebpackPlugin = require('js-config-webpack-plugin');
34

5+
const defaultOutputPath = resolve(join(process.cwd(), 'dist'));
6+
47
module.exports = {
58
mode: 'production',
69
entry: './index.js',
710
plugins: [new JsConfigWebpackPlugin()],
8-
11+
output: {
12+
path: defaultOutputPath,
13+
filename: 'bundle.js'
14+
},
915
optimization: {
1016
minimizer: [new TerserPlugin()],
1117
},

lib/webpack-cli.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { join } = require('path');
1+
const { resolve, parse, join } = require('path');
22
const { existsSync } = require('fs');
33
const GroupHelper = require('./utils/group-helper');
44
const Compiler = require('./utils/compiler');
@@ -11,7 +11,6 @@ class WebpackCLI extends GroupHelper {
1111
this.groupMap = new Map();
1212
this.groups = [];
1313
this.processingErrors = [];
14-
this.shouldUseMem = false;
1514
}
1615
setMappedGroups(args, yargsOptions) {
1716
const { _all } = args;
@@ -32,7 +31,9 @@ class WebpackCLI extends GroupHelper {
3231
}
3332

3433
checkDefaults(options) {
35-
const { resolve, parse } = require('path');
34+
if (Array.isArray(options)) {
35+
return options.map(opt => this.checkDefaults(opt));
36+
}
3637
const defaultEntry = 'index';
3738
const possibleFileNames = [
3839
`./${defaultEntry}`, `./${defaultEntry}.js`, `${defaultEntry}.js`, defaultEntry,
@@ -56,8 +57,6 @@ class WebpackCLI extends GroupHelper {
5657
}
5758

5859
}
59-
} else if (Array.isArray(options)) {
60-
return options.map(opt => this.checkDefaults(opt));
6160
}
6261
return options;
6362
}
@@ -144,7 +143,7 @@ class WebpackCLI extends GroupHelper {
144143

145144
async run(args, yargsOptions) {
146145
const groupResult = await this.processArgs(args, yargsOptions);
147-
const webpack = await Compiler.webpackInstance(groupResult, this.shouldUseMem);
146+
const webpack = await Compiler.webpackInstance(groupResult);
148147
return webpack;
149148
}
150149

0 commit comments

Comments
 (0)