-
-
Notifications
You must be signed in to change notification settings - Fork 503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webpack plugins don't get added #244
Comments
I'll look into it, and come back to you soon |
@AndrewCraswell your repro case doesn't look like it have craco. Is it possible you forgot to push some of your code? |
@alexasselin008 Sorry about that, I've just pushed an update |
I am having the same issue. Additionally remove is not working for me. |
@AndrewCraswell I looked at your sandbox and it should work fine if you use build. I created a file outputWebpackConfig.js
then i ran the following command line :
The script console logs the webpack config, where you can see the plugins and both plugin are added. @b-zurg would you mind detailing your issue a bit more? |
@alexasselin008 Thanks for the <meta http-equiv="Content-Security-Policy" content="base-uri 'self'; object-src 'none'; script-src 'unsafe-inline' 'self' 'unsafe-eval' 'nonce-5c504VCl7tqV5T87ckQxUA==' 'nonce-dU8Pu5WgPBXD7M02R2B+Gg==' 'nonce-SU0gjUzE62GbUHoh9Afdpw=='; style-src 'unsafe-inline' 'self' 'unsafe-eval' 'nonce-tL5Q1BDaTYqEUp4oCH/X1w=='"> However, if I eject, and add the same plugin in the same order that Craco reported having added it, everything works as expected and the plugin is executed. I've added a PR to the repro repository to show how just ejecting and adding the plugin works: It's worth mentioning that I've experienced this with a number of plugins as well, this isn't the only one. |
As an aside, there's also some wonkiness with the Craco module.exports = {
webpack: {
plugins: {
remove: [...whenProd(() => ["HtmlWebpackPlugin"], [])],
add: [
...whenProd(
() => [
new HtmlWebpackPlugin({
inject: true,
template: paths.appHtml,
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
}),
new CspHtmlWebpackPlugin(),
],
[]
),
],
},
},
}; My expectation is that this would remove the |
It's hard to tell if this is a problem with Craco, or with The only way I've been able to get these plugins to work from the Craco config is by removing the A workaround is to remove the CRA plugins via Craco, then also use Craco to add a new instance configured in an identical way, then add any new plugins (ex: module.exports = {
webpack: {
plugins: {
remove: [...whenProd(() => ['HtmlWebpackPlugin', 'InterpolateHtmlPlugin ', 'InlineChunkHtmlPlugin'], [])],
add: [
...whenProd(
() =>
[
new HtmlWebpackPlugin({
inject: true,
template: paths.appHtml,
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
}),
new InterpolateHtmlPlugin(HtmlWebpackPlugin, options),
shouldInlineRuntimeChunk && new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime-.+[.]js/]),
new CspHtmlWebpackPlugin(),
].filter(Boolean),
[]
),
],
},
}
}; This gives the same functionality offered by CRA, but adds the This should work, except for the issue mentioned in the previous comment about the |
Since the fix that enables a workaround has been merged, I'm going to close this. I suspect the issue is related to weirdness in the |
I think this issue might be related to this comment So far I came accross 2 things:
What might solve the issue (feature request) would be pushing new plugins to the end of plugins array (or have this configurable.) |
So I would propose changing this
into something like this:
I am not sure if this would be a breaking change tho. |
Craco:
6.1.0
CRA:
4.0.1
I've recently tried to add the
CspHtmlWebpackPlugin
to mycraco.config.js
file in order to dynamically inject a Content Security Policy into my site only during production builds. It seems the plugin is not being added correctly, and a number of other plugins I've tested don't get added either. This is especially odd because my config already had theBundleAnalyzerPlugin
plugin being added which did work.I've tried ejecting from CRA and adding the same plugins to the webpack config directly and everything works as I would expect. Maybe related to this recent change? #224
Here is a minimalistic repository that repros the issue:
https://github.com/AndrewCraswell/craco-bug
The text was updated successfully, but these errors were encountered: