mirror of
https://github.com/scratchfoundation/scratch-webpack-configuration.git
synced 2024-11-27 10:05:37 -05:00
Merge pull request #1 from MiroslavDionisiev/UEPR-17
[UEPR-17] Add flag for omitting chunk splitting and added logic to exclude node_modules
This commit is contained in:
commit
d44b4d2509
1 changed files with 20 additions and 7 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.shouldSplitChunks] Whether to enable spliting code to chunks.
|
||||
*/
|
||||
constructor ({distPath, enableReact, libraryName, rootPath, srcPath}) {
|
||||
constructor ({ distPath, enableReact, libraryName, rootPath, srcPath, shouldSplitChunks }) {
|
||||
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._shouldSplitChunks = shouldSplitChunks
|
||||
|
||||
/**
|
||||
* @type {Configuration}
|
||||
|
@ -54,11 +56,15 @@ class ScratchWebpackConfigBuilder {
|
|||
} : path.resolve(this._srcPath, 'index'),
|
||||
optimization: {
|
||||
minimize: isProduction,
|
||||
splitChunks: {
|
||||
chunks: 'all',
|
||||
filename: DEFAULT_CHUNK_FILENAME
|
||||
},
|
||||
mergeDuplicateChunks: true
|
||||
...(
|
||||
shouldSplitChunks ? {
|
||||
splitChunks: {
|
||||
chunks: 'all',
|
||||
filename: DEFAULT_CHUNK_FILENAME,
|
||||
},
|
||||
mergeDuplicateChunks: true
|
||||
} : {}
|
||||
)
|
||||
},
|
||||
output: {
|
||||
clean: true,
|
||||
|
@ -91,6 +97,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 +151,8 @@ class ScratchWebpackConfigBuilder {
|
|||
libraryName: this._libraryName,
|
||||
rootPath: this._rootPath,
|
||||
srcPath: this._srcPath,
|
||||
distPath: this._distPath
|
||||
distPath: this._distPath,
|
||||
shouldSplitChunks: this._shouldSplitChunks
|
||||
}).merge(this._config);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue