I'm trying to add the webpack style-loader nonce attribute to a craco config file, for a create-react-app, like this:
// craco.config.js
module.exports = {
webpack: {
module: {
rules: [
{
test: /\.css$/i,
use: [
{
loader: "style-loader",
options: {
attributes: {
nonce: "12345678",
},
},
},
"css-loader",
],
},
],
},
},
};
but that didn't work. Does anyone if this can be achieved with craco and how?.
Problem
cracodoesn't offer you to modifymodule.rulesdirectly that way.Solution
Instead it offers you
webpack.configuremethod instead which takes following signature:configure: (webpackConfig, { env, paths }) => { return webpackConfig; }In order to override
style-loader(only supportdevelopmentmode), you would need a few helper functions. Here is the idea for you: