我想创建React组件,将js和css保存在同一个文件夹中(对于每个组件):
以下是我的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代码。那么如何解决呢?
答案 0 :(得分:0)
当我从laravel-elixir-webpack-official
切换到本地webpack
(webpack-stream)时修复了