-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: if used
splitChunks.chunks
option then this options will be re…
…moved and will be displayed a warning
- Loading branch information
Showing
20 changed files
with
246 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const { greenBright, redBright, reset, black } = require('ansis'); | ||
const { outToConsole } = require('../../Common/Helpers'); | ||
const Config = require('../../Common/Config'); | ||
|
||
const { pluginLabel } = Config.get(); | ||
const headerWarning = `\n${reset.black.bgYellow` ${pluginLabel} ${black.bg(227)` WARNING `}`}\n`; | ||
|
||
const optionSplitChunksChunksAllWarning = () => { | ||
const message = `DO NOT use the ${redBright`chunks: 'all'`} option globally! | ||
The ${redBright`splitChunks.chunks`} option is automatically deleted, because it corrupts output files generated by this plugin! | ||
${black.bgYellowBright` SOLUTION `} | ||
Define the ${greenBright`chunks`} option in ${greenBright`'splitChunks.cacheGroups.{group}.chunks'`}, e.g.: | ||
splitChunks: { | ||
${redBright`- chunks: 'all',`} // <= DO NOT use this here | ||
cacheGroups: { | ||
myGroup: { | ||
test: /\\.(js|ts)$/, // <= IMPORTANT: split only script files | ||
${greenBright`+ chunks: 'all',`} // <= DEFINE it here only | ||
}, | ||
}, | ||
}, | ||
`; | ||
|
||
outToConsole(headerWarning + message); | ||
}; | ||
|
||
module.exports = { | ||
optionSplitChunksChunksAllWarning, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Test</title> | ||
</head> | ||
<body> | ||
<h1>Hello World!</h1> | ||
</body> | ||
</html> |
36 changes: 36 additions & 0 deletions
36
test/cases/_warnings/msg-warning-splitChunks/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const path = require('path'); | ||
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin'); | ||
|
||
module.exports = { | ||
mode: 'production', | ||
|
||
output: { | ||
path: path.join(__dirname, 'dist/'), | ||
}, | ||
|
||
plugins: [ | ||
new HtmlBundlerPlugin({ | ||
entry: { | ||
index: './src/index.html', | ||
}, | ||
}), | ||
], | ||
|
||
optimization: { | ||
splitChunks: { | ||
chunks: 'all', // <= DO NOT use this here, it doesn't make sense because we will split only scripts in a group | ||
cacheGroups: { | ||
vendor: { | ||
test: /[\\/]node_modules[\\/].+\.(js|ts)$/, // <= IMPORTANT: split only script files | ||
name: 'vendor', | ||
chunks: 'all', // <= DEFINE `chunks: 'all'` only in a cache group | ||
}, | ||
default: { | ||
minChunks: 2, | ||
reuseExistingChunk: true, | ||
enforce: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; |
11 changes: 11 additions & 0 deletions
11
test/cases/resolve-image-in-multipages-splitChunks/expected/about.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<h1>About</h1> | ||
<!-- test resolving the same image in diff templates: ERROR --> | ||
<img src="img/apple.02a7c382.png" /> | ||
<!-- test resolving the diff image in diff templates: OK --> | ||
<img src="img/pear.6b9b072a.png" /> | ||
</body> | ||
</html> |
Binary file added
BIN
+1.74 KB
test/cases/resolve-image-in-multipages-splitChunks/expected/img/apple.02a7c382.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.72 KB
test/cases/resolve-image-in-multipages-splitChunks/expected/img/pear.6b9b072a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions
9
test/cases/resolve-image-in-multipages-splitChunks/expected/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<h1>Home</h1> | ||
<!-- test resolving the same image in diff templates --> | ||
<img src="img/apple.02a7c382.png" /> | ||
</body> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
test/cases/resolve-image-in-multipages-splitChunks/src/about.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<h1>About</h1> | ||
<!-- test resolving the same image in diff templates: ERROR --> | ||
<img src="@images/apple.png" /> | ||
<!-- test resolving the diff image in diff templates: OK --> | ||
<img src="@images/pear.png" /> | ||
</body> | ||
</html> |
9 changes: 9 additions & 0 deletions
9
test/cases/resolve-image-in-multipages-splitChunks/src/home.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<h1>Home</h1> | ||
<!-- test resolving the same image in diff templates --> | ||
<img src="@images/apple.png" /> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('>> main.js'); |
61 changes: 61 additions & 0 deletions
61
test/cases/resolve-image-in-multipages-splitChunks/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const path = require('path'); | ||
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin'); | ||
|
||
module.exports = { | ||
mode: 'production', | ||
|
||
output: { | ||
path: path.join(__dirname, 'dist/'), | ||
}, | ||
|
||
resolve: { | ||
alias: { | ||
'@images': path.join(__dirname, '../../fixtures/images'), | ||
}, | ||
}, | ||
|
||
plugins: [ | ||
new HtmlBundlerPlugin({ | ||
entry: { | ||
index: './src/home.html', | ||
about: './src/about.html', | ||
}, | ||
|
||
verbose: true, | ||
}), | ||
], | ||
|
||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: ['css-loader'], | ||
}, | ||
{ | ||
test: /\.(png|jpe?g|webp|ico|svg)$/, | ||
type: 'asset/resource', | ||
generator: { | ||
filename: 'img/[name].[hash:8][ext]', | ||
}, | ||
}, | ||
], | ||
}, | ||
|
||
optimization: { | ||
splitChunks: { | ||
chunks: 'all', // <= DO NOT use this here, it doesn't make sense because we will split only scripts in a group | ||
cacheGroups: { | ||
vendor: { | ||
test: /[\\/]node_modules[\\/].+\.(js|ts)$/, // <= IMPORTANT: split only script files | ||
name: 'vendor', | ||
chunks: 'all', // <= DEFINE `chunks: 'all'` only in a cache group | ||
}, | ||
default: { | ||
minChunks: 2, | ||
reuseExistingChunk: true, | ||
enforce: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.