Skip to content

Commit

Permalink
FIX Fix devtool error and remove comments in prod (#54)
Browse files Browse the repository at this point in the history
* FIX Devtool cannot be an empty string

* FIX Don't include comments in javascript output
  • Loading branch information
GuySartorelli authored Dec 12, 2022
1 parent 071271b commit 31d1dfe
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ module.exports = [
path: PATHS.DIST,
filename: 'js/[name].js',
},
devtool: (ENV !== 'production') ? 'source-map' : '',
devtool: (ENV !== 'production') ? 'source-map' : false,
resolve: resolveJS(ENV, PATHS),
externals: externalJS(ENV, PATHS),
module: moduleJS(ENV, PATHS),
Expand All @@ -228,7 +228,7 @@ module.exports = [
output: {
path: PATHS.DIST,
},
devtool: (ENV !== 'production') ? 'source-map' : '',
devtool: (ENV !== 'production') ? 'source-map' : false,
module: moduleCSS(ENV, PATHS),
// Pass the filename here, which will get passed down to MiniCssExtractPlugin
plugins: pluginCSS(ENV, PATHS, 'css/[name].css'),
Expand Down
22 changes: 12 additions & 10 deletions configMeta/baseWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,21 @@ module.exports = class BaseWebpackConfig {

this.#vendorChunk = vendorChunk;

this.#config.optimization = {
splitChunks: {
cacheGroups: {
vendor: {
name: vendorChunk,
test: test,
reuseExistingChunk: true,
enforce: true,
chunks: 'all',
this.mergeConfig({
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
name: vendorChunk,
test: test,
reuseExistingChunk: true,
enforce: true,
chunks: 'all',
}
}
}
}
};
});

// ensure entries are configured to "depend on" the vendor entry if necessary
this.#splitVendorFromEntries();
Expand Down
2 changes: 1 addition & 1 deletion configMeta/cssWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = class CssWebpackConfig extends BaseWebpackConfig {
output: {
path: PATHS.DIST,
},
devtool: (ENV !== 'production') ? 'source-map' : '',
devtool: (ENV !== 'production') ? 'source-map' : false,
module: moduleCSS(ENV, PATHS),
plugins: pluginCSS(ENV, PATHS, filename),
});
Expand Down
16 changes: 15 additions & 1 deletion configMeta/javascriptWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const externalJS = require('../js/externals');
const moduleJS = require('../js/modules');
const pluginJS = require('../js/plugins');
const resolveJS = require('../js/resolve');
const TerserPlugin = require('terser-webpack-plugin');

/**
* Dynamically generates webpack config for transpiling javascript using Silverstripe default settings
Expand All @@ -19,11 +20,24 @@ module.exports = class JavascriptWebpackConfig extends BaseWebpackConfig {
path: PATHS.DIST,
filename: 'js/[name].js',
},
devtool: (ENV !== 'production') ? 'source-map' : '',
devtool: (ENV !== 'production') ? 'source-map' : false,
resolve: resolveJS(ENV, PATHS),
module: moduleJS(ENV, PATHS),
externals: externalJS(ENV, PATHS, moduleName),
plugins: pluginJS(ENV),
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
format: {
comments: false,
},
},
}),
],
},
});
}
}

0 comments on commit 31d1dfe

Please sign in to comment.