diff --git a/src/index.cjs b/src/index.cjs index c241877..cded4a2 100644 --- a/src/index.cjs +++ b/src/index.cjs @@ -38,8 +38,9 @@ class ScratchWebpackConfigBuilder { * @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. + * @param {RegExp[]} [options.cssModuleExceptions] Optional array of regex rules that exclude matching CSS files from CSS module scoping. */ - constructor ({ distPath, enableReact, enableTs, libraryName, rootPath, srcPath, publicPath = '/', shouldSplitChunks }) { + constructor ({ distPath, enableReact, enableTs, libraryName, rootPath, srcPath, publicPath = '/', shouldSplitChunks, cssModuleExceptions = [] }) { const isProduction = process.env.NODE_ENV === 'production'; const mode = isProduction ? 'production' : 'development'; @@ -184,6 +185,7 @@ class ScratchWebpackConfigBuilder { enableReact ? [ { test: /\.css$/, + exclude: cssModuleExceptions, use: [ { loader: 'style-loader' @@ -213,6 +215,25 @@ class ScratchWebpackConfigBuilder { } } ] + }, + { + test: cssModuleExceptions, + use: [ + 'style-loader', + 'css-loader', + { + loader: 'postcss-loader', + options: { + postcssOptions: { + plugins: [ + 'postcss-import', + 'postcss-simple-vars', + 'autoprefixer' + ] + } + } + } + ] } ] : [] ),