我看到了FlipKart,他们对所有的 classNames 和它的 CSSes 进行了哈希处理。我知道他们使用 SCSS 来构建 CSS。如何配置我的 WebPack 以使我的导出类似于他们的:
这是我的 webpack:
var webpack = require('webpack'),
path = require('path'),
ExtractTextPlugin = require('extract-text-webpack-plugin'),
UglifyJSPlugin = require('uglifyjs-webpack-plugin'),
OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
var DistDir = path.resolve(__dirname, 'app/dist'),
SrcDir = path.resolve(__dirname, 'app/src');
module.exports = {
entry: SrcDir,
output: {
path: DistDir,
filename: "bundle.min.js"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
include: SrcDir,
loader: 'babel-loader'
},
{
test: /\.(scss|css)$/,
exclude: /node_modules/,
use: ExtractTextPlugin.extract({
use: [{
loader: "css-loader", options: {
modules: true,
localIdentName: '[hash:base64:3]',
sourceMap: false
}
}, {
loader: "sass-loader", options: {
sourceMap: false
}
}],
fallback: "style-loader"
})
},
{
test: /\.png$/,
loader: "file-loader",
exclude: /node_modules/
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new ExtractTextPlugin("bundle.min.css"),
new OptimizeCssAssetsPlugin({
cssProcessor: require('cssnano'),
cssProcessorOptions: { discardComments: {removeAll: true } },
canPrint: true
}),
new UglifyJSPlugin({
compress: {
unused: true,
dead_code: true,
warnings: false,
drop_debugger: true,
conditionals: true,
evaluate: true,
drop_console: true,
sequences: true,
booleans: true
},
comments: false
}),
new webpack.IgnorePlugin(/^\.\/locale$/, [/moment$/]),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.optimize.AggressiveMergingPlugin()
]
};
但它只是散列我在 CSS 文件中的类名,而 DOM 中的类名是开发版本,例如 DOM 中的类名元素之一是product__bag--red
,它在 CSS 文件中的类名是_1x4
.
我如何为我看到_1x4
的而不是product__bag--red
在 DOM 中配置 webpack 或 extract-text-plugin?