mirror of
https://github.com/scratchfoundation/scratch-webpack-configuration.git
synced 2024-11-27 10:05:37 -05:00
refactor: [UEPR-17] Set optimization to be optional and added exclude logic
This commit is contained in:
parent
1e77df3ec1
commit
c89bfcd099
1 changed files with 21 additions and 10 deletions
|
@ -33,8 +33,9 @@ class ScratchWebpackConfigBuilder {
|
|||
* @param {boolean} [options.enableReact] Whether to enable React and JSX support.
|
||||
* @param {string} [options.libraryName] The name of the library to build. Shorthand for `output.library.name`.
|
||||
* @param {string|URL} [options.srcPath] The absolute path to the source files. Defaults to `src` under `rootPath`.
|
||||
* @param {boolean} [options.shouldOptimize] Whether to enable optimization.
|
||||
*/
|
||||
constructor ({distPath, enableReact, libraryName, rootPath, srcPath}) {
|
||||
constructor({ distPath, enableReact, libraryName, rootPath, srcPath, shouldOptimize}) {
|
||||
const isProduction = process.env.NODE_ENV === 'production';
|
||||
const mode = isProduction ? 'production' : 'development';
|
||||
|
||||
|
@ -42,6 +43,7 @@ class ScratchWebpackConfigBuilder {
|
|||
this._rootPath = toPath(rootPath) || '.'; // '.' will cause a webpack error since src must be absolute
|
||||
this._srcPath = toPath(srcPath) ?? path.resolve(this._rootPath, 'src');
|
||||
this._distPath = toPath(distPath) ?? path.resolve(this._rootPath, 'dist');
|
||||
this._shouldOptimize = shouldOptimize
|
||||
|
||||
/**
|
||||
* @type {Configuration}
|
||||
|
@ -52,14 +54,16 @@ class ScratchWebpackConfigBuilder {
|
|||
entry: libraryName ? {
|
||||
[libraryName]: path.resolve(this._srcPath, 'index')
|
||||
} : path.resolve(this._srcPath, 'index'),
|
||||
optimization: {
|
||||
minimize: isProduction,
|
||||
splitChunks: {
|
||||
chunks: 'all',
|
||||
filename: DEFAULT_CHUNK_FILENAME
|
||||
},
|
||||
mergeDuplicateChunks: true
|
||||
},
|
||||
optimization: shouldOptimize
|
||||
? {
|
||||
minimize: isProduction,
|
||||
splitChunks: {
|
||||
chunks: 'all',
|
||||
filename: DEFAULT_CHUNK_FILENAME,
|
||||
},
|
||||
mergeDuplicateChunks: true,
|
||||
}
|
||||
: {},
|
||||
output: {
|
||||
clean: true,
|
||||
filename: '[name].js',
|
||||
|
@ -91,6 +95,12 @@ class ScratchWebpackConfigBuilder {
|
|||
{
|
||||
test: enableReact ? /\.[cm]?jsx?$/ : /\.[cm]?js$/,
|
||||
loader: 'babel-loader',
|
||||
exclude: [
|
||||
{
|
||||
and: [/node_modules/],
|
||||
not: [/node_modules\/scratch-/]
|
||||
}
|
||||
],
|
||||
options: {
|
||||
presets: [
|
||||
'@babel/preset-env',
|
||||
|
@ -139,7 +149,8 @@ class ScratchWebpackConfigBuilder {
|
|||
libraryName: this._libraryName,
|
||||
rootPath: this._rootPath,
|
||||
srcPath: this._srcPath,
|
||||
distPath: this._distPath
|
||||
distPath: this._distPath,
|
||||
shouldOptimize: this._shouldOptimize
|
||||
}).merge(this._config);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue