[英]How to remove css from js bundle?
我想創建將js和css放在同一文件夾中的React組件(對於每個組件):
這是我的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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.