mirror of
https://github.com/scratchfoundation/scratch-webpack-configuration.git
synced 2024-11-24 00:27:53 -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 {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} [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 {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 isProduction = process.env.NODE_ENV === 'production';
|
||||||
const mode = isProduction ? 'production' : 'development';
|
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._rootPath = toPath(rootPath) || '.'; // '.' will cause a webpack error since src must be absolute
|
||||||
this._srcPath = toPath(srcPath) ?? path.resolve(this._rootPath, 'src');
|
this._srcPath = toPath(srcPath) ?? path.resolve(this._rootPath, 'src');
|
||||||
this._distPath = toPath(distPath) ?? path.resolve(this._rootPath, 'dist');
|
this._distPath = toPath(distPath) ?? path.resolve(this._rootPath, 'dist');
|
||||||
|
this._shouldSplitChunks = shouldSplitChunks
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Configuration}
|
* @type {Configuration}
|
||||||
|
@ -54,11 +56,15 @@ class ScratchWebpackConfigBuilder {
|
||||||
} : path.resolve(this._srcPath, 'index'),
|
} : path.resolve(this._srcPath, 'index'),
|
||||||
optimization: {
|
optimization: {
|
||||||
minimize: isProduction,
|
minimize: isProduction,
|
||||||
splitChunks: {
|
...(
|
||||||
chunks: 'all',
|
shouldSplitChunks ? {
|
||||||
filename: DEFAULT_CHUNK_FILENAME
|
splitChunks: {
|
||||||
},
|
chunks: 'all',
|
||||||
mergeDuplicateChunks: true
|
filename: DEFAULT_CHUNK_FILENAME,
|
||||||
|
},
|
||||||
|
mergeDuplicateChunks: true
|
||||||
|
} : {}
|
||||||
|
)
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
clean: true,
|
clean: true,
|
||||||
|
@ -91,6 +97,12 @@ class ScratchWebpackConfigBuilder {
|
||||||
{
|
{
|
||||||
test: enableReact ? /\.[cm]?jsx?$/ : /\.[cm]?js$/,
|
test: enableReact ? /\.[cm]?jsx?$/ : /\.[cm]?js$/,
|
||||||
loader: 'babel-loader',
|
loader: 'babel-loader',
|
||||||
|
exclude: [
|
||||||
|
{
|
||||||
|
and: [/node_modules/],
|
||||||
|
not: [/node_modules[\\/].*scratch/]
|
||||||
|
}
|
||||||
|
],
|
||||||
options: {
|
options: {
|
||||||
presets: [
|
presets: [
|
||||||
'@babel/preset-env',
|
'@babel/preset-env',
|
||||||
|
@ -139,7 +151,8 @@ class ScratchWebpackConfigBuilder {
|
||||||
libraryName: this._libraryName,
|
libraryName: this._libraryName,
|
||||||
rootPath: this._rootPath,
|
rootPath: this._rootPath,
|
||||||
srcPath: this._srcPath,
|
srcPath: this._srcPath,
|
||||||
distPath: this._distPath
|
distPath: this._distPath,
|
||||||
|
shouldSplitChunks: this._shouldSplitChunks
|
||||||
}).merge(this._config);
|
}).merge(this._config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue