-
-
Notifications
You must be signed in to change notification settings - Fork 622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli(init): Better defaults #451
Changes from 2 commits
821c753
8dcc4ac
cf8b1d5
b64f780
359aef5
52ca883
3c5057c
fc52290
5fdb178
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,14 @@ module.exports = class InitGenerator extends Generator { | |
constructor(args, opts) { | ||
super(args, opts); | ||
this.isProd = false; | ||
this.dependencies = ["webpack", "webpack-cli", "uglifyjs-webpack-plugin"]; | ||
(this.usingDefaults = false), | ||
(this.dependencies = [ | ||
"webpack", | ||
"webpack-cli", | ||
"uglifyjs-webpack-plugin", | ||
"babel-plugin-syntax-dynamic-import", | ||
"path" | ||
]); | ||
this.configuration = { | ||
config: { | ||
webpackOptions: {}, | ||
|
@@ -93,20 +100,25 @@ module.exports = class InitGenerator extends Generator { | |
.then(outputTypeAnswer => { | ||
// As entry is not required anymore and we dont set it to be an empty string or """"" | ||
// it can be undefined so falsy check is enough (vs entry.length); | ||
if (!this.configuration.config.webpackOptions.entry) { | ||
if ( | ||
!this.configuration.config.webpackOptions.entry && | ||
!this.usingDefaults | ||
) { | ||
this.configuration.config.webpackOptions.output = { | ||
filename: "'[name].[chunkhash].js'", | ||
chunkFilename: "'[name].[chunkhash].js'" | ||
}; | ||
} else { | ||
} else if (!this.usingDefaults) { | ||
this.configuration.config.webpackOptions.output = { | ||
filename: "'[name].[chunkhash].js'" | ||
}; | ||
} | ||
if (outputTypeAnswer["outputType"].length) { | ||
outputPath = outputTypeAnswer["outputType"]; | ||
} | ||
this.configuration.config.webpackOptions.output.path = `path.resolve(__dirname, '${outputPath}')`; | ||
if (!this.usingDefaults) { | ||
this.configuration.config.webpackOptions.output.path = `path.resolve(__dirname, '${outputPath}')`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am kinda worried about this level of nesting, won't it impact performance ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know. It's not a super-big generator, so it might be a premature optimization? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say that we have to think about optimisation in advance There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 |
||
} | ||
}) | ||
.then(() => { | ||
return this.prompt([ | ||
|
@@ -394,9 +406,13 @@ module.exports = class InitGenerator extends Generator { | |
done(); | ||
}); | ||
} | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this commented code? If so, it can be removed |
||
installPlugins() { | ||
const asyncNamePrompt = this.async(); | ||
const defaultName = this.isProd ? "prod" : "config"; | ||
if(this.isProd) { | ||
this.dependencies = this.dependencies.filter(p => p !== "uglifyjs-webpack-plugin"); | ||
} | ||
this.prompt([ | ||
Input( | ||
"nameType", | ||
|
@@ -415,6 +431,7 @@ module.exports = class InitGenerator extends Generator { | |
this.runInstall(packager, this.dependencies, opts); | ||
}); | ||
} | ||
*/ | ||
|
||
writing() { | ||
this.config.set("configuration", this.configuration); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,13 @@ | |
module.exports = _ => { | ||
return { | ||
test: `${new RegExp(/\.js$/)}`, | ||
exclude: "/node_modules/", | ||
include: ["path.resolve(__dirname, 'src')"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sokra just wondering. If the entry folder is different, then this would need to change, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just curious, can't we take this from the If not present then use this as a default value |
||
loader: "'babel-loader'", | ||
options: { | ||
presets: ["'env'"] | ||
presets: ["'env'", { | ||
modules: false | ||
}], | ||
plugins: ["'syntax-dynamic-import'"] | ||
} | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,9 @@ module.exports = function recursiveTransform(j, ast, value, action, key) { | |
} else if (key === "merge") { | ||
utils.parseMerge(j, p, value); | ||
} else { | ||
utils.addProperty(j, p, key, value); | ||
if (value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. old commit |
||
utils.addProperty(j, p, key, value); | ||
} | ||
} | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't
path
core Node.js module?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it can be accessed only after defining.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but these are packages that would get installed by npm/yarn, right? Definition part would be in topScope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes exactly.
path
needs to be removed