Skip to content

Instantly share code, notes, and snippets.

@jakoblind
Created October 8, 2019 06:24
Show Gist options
  • Save jakoblind/cfef01f3a9fd912eb14e05d06e43cfc3 to your computer and use it in GitHub Desktop.
Save jakoblind/cfef01f3a9fd912eb14e05d06e43cfc3 to your computer and use it in GitHub Desktop.
diff --git a/src/configurator/configurator.js b/src/configurator/configurator.js
index 9dfcabb..3b18a36 100644
--- a/src/configurator/configurator.js
+++ b/src/configurator/configurator.js
@@ -108,41 +108,35 @@ function createHotReloadModifier(configItems) {
return null
}
- return (
-` if (argv.hot) {
+ // More info here: https://stackoverflow.com/questions/50217480/cannot-use-chunkhash-or-contenthash-for-chunk-in-name-chunkhash-js-us/50217641#50217641
+ return `if (argv.hot) {
// Cannot use 'contenthash' when hot reloading is enabled.
config.output.filename = '[name].[hash].js';
}
`
- )
}
-export function createWebpackConfig(configItems) {
- const imports = _.concat(baseWebpackImports, getWebpackImports(configItems))
- const importsLines = imports.join('\n')
- const config = createConfig(configItems, 'webpack')
+function createWebpackConfigExportStatement(configItems) {
const hotReloadModifier = createHotReloadModifier(configItems)
-
if (!hotReloadModifier) {
- return (
-`${importsLines}
-
-module.exports = ${config};
-`
- )
+ return `config`
}
- return (
-`${importsLines}
-
-const config = ${config};
-
-module.exports = (env, argv) => {
+ return `(env, argv) => {
${hotReloadModifier}
return config;
-};
-`
- )
+}`
+}
+
+export function createWebpackConfig(configItems) {
+ const imports = _.concat(baseWebpackImports, getWebpackImports(configItems))
+ const importsLines = imports.join('\n')
+ const config = createConfig(configItems, 'webpack')
+ const exportStatement = createWebpackConfigExportStatement(configItems)
+
+ return `${importsLines}
+const config = ${config}
+module.exports = ${exportStatement};`
}
// some config items can alter the package json. for example the scripts section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment