时修复了
我想创建将JS和CSS保存在同一文件夹中(对于每个组件)的组件:
- 对话框
- container.jsx
- presentation.jsx
- 样式。
这是我的WebPack配置的一部分:
module: {
loaders: [
{
test: /.(js|jsx)$/,
loader: 'babel',
exclude: /(node_modules)/,
query: {
presets: [
['react'],
['es2015'],
['stage-0']
],
plugins: [
['transform-decorators-legacy'],
['transform-runtime'],
['transform-react-remove-prop-types'],
['transform-react-constant-elements'],
['transform-react-inline-elements']
]
}
},
{
test: /.less$/,
loader: ExtractTextPlugin.extract(['css-loader', 'less-loader']),
}
],
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.ProvidePlugin({
'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch'
}),
new webpack.optimize.UglifyJsPlugin({
beautify: false,
comments: false,
sourceMap: true,
compress: {
sequences: true,
booleans: true,
loops: true,
unused: true,
warnings: false,
drop_console: true,
unsafe: true
}
}),
new ExtractTextPlugin({
filename: 'bundle.css',
allChunks: true
}),
new OptimizeCssAssetsPlugin({
assetNameRegExp: /.css$/g,
cssProcessor: require('cssnano'),
cssProcessorOptions: {
discardComments: {
removeAll: true
}
},
canPrint: true
})
],
WebPack创建bundle.js
bundle.css
文件。我会说除了一刻,它的工作原理。我发现bundle.js
包含来自bundle.css
的CSS。
例如,如果bundle.css
的大小为50kb,则bundle.js
=自己的大小 50KB。
我不需要在JS捆绑包中重复的CSS代码。那么如何修复呢?
我从laravel-elixir-webpack-official
切换到本机webpack
(webpack-stream)