我正在使用 CSS 模块有条件地加载顶级样式表(手写笔)。这在我运行 webpack-dev-server 时工作正常,但我正在尝试生成 2 个 CSS 文件:theme1.css 和 theme2.css。
这是顶级index.js文件。
export function loadStylesheet() {
if (condition1) {
require('../../styles/theme1.styl');
} else {
require('../../styles/theme2.styl');
}
}
Webpack 这里是 webpack.config.prod.js
// ...
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: [
/node_modules/,
/src\/lib/
],
loaders: ['babel', 'eslint-loader']
},
{
test: /\.html$/,
loader: 'file?name=[name].[ext]'
},
{
test: /\.styl$/,
include: path.join(__dirname, 'src', 'styles'),
loader: ExtractTextPlugin.extract('style', '!css?-url!postcss!stylus')
},
{
test: /\.jpg|.png|.gif|.otf$/,
loader: 'file?name=[path][name].[ext]'
}
]
},
plugins: [
// ...
new ExtractTextPlugin('css/style.css', { allChunks: true })
]
// ...