dflzm
Version:
x
153 lines (148 loc) • 4.01 kB
JavaScript
const webpack = require('webpack')
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const StylelintWebpackPlugin = require('stylelint-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const env = process.env.NODE_ENV
const mode = env === 'development' || env === 'wds' ? 'development' : 'production'
module.exports = {
target: 'web',
mode: mode,
entry: {
app: ['./client/client.jsx']
},
output: {
path: path.resolve(__dirname, '../asset/'),
filename: 'script/[name].js',
publicPath: '/',
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react']
}
}, {
loader: 'eslint-loader'
}
]
}, {
test: /\.sass$/,
use: [
'css-hot-loader',
MiniCssExtractPlugin.loader,
{
loader: 'css-loader?importLoaders=1',
options: {
modules: true,
localIdentName: '[name]_[local]_[hash:base64:5]',
minimize: true
}
}, {
loader: 'sass-loader',
options: {
javascriptEnabled: true
}
}
]
}, {
test: /\.scss$/,
use: [
'css-hot-loader',
MiniCssExtractPlugin.loader,
{
loader: 'css-loader?importLoaders=1',
options: {
modules: true,
// localIdentName: '[name]_[local]_[hash:base64:5]',
localIdentName: '[local]_[hash:base64:5]',
minimize: true
}
}, {
loader: 'sass-loader',
options: {
javascriptEnabled: true
}
}
]
}, {
test: /\.(less|css)$/,
use: [
'css-hot-loader',
MiniCssExtractPlugin.loader,
{
loader: 'css-loader?importLoaders=1',
options: {
modules: true,
// localIdentName: '[name]_[local]_[hash:base64:5]',
localIdentName: '[local]_[hash:base64:5]',
minimize: true
}
}, {
loader: 'less-loader',
options: {
javascriptEnabled: true
}
}
]
}, {
test: /\.(png|jpg|gif|md)$/,
use: ['file-loader?limit=10000&name=image/[md5:hash:base64:10].[ext]']
}, {
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
use: ['url-loader?limit=10000&mimetype=images/svg+xml']
}, {
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
}, {
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
}, {
test: /\.json$/,
use: 'json-loader'
}
]
},
devtool: 'cheap-module-source-map',
resolve: {
extensions: ['.js', '.jsx', '.scss', '.less', '.jpg', '.jpeg', '.png', '.gif', '.svg']
},
plugins: [
new MiniCssExtractPlugin({
filename: 'style/[name].css',
chunkFilename: '[id].css'
}),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./reactFest.json')
}),
new StylelintWebpackPlugin({
context: 'client',
files: '**/*.scss',
emitErrors: true,
configFile: '.stylelintrc.js',
failOnError: false,
quiet: false,
}),
],
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true
}),
new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
map: { inline: false }
}
})
]
},
}