mirror of
https://gitee.com/freshday/radar.git
synced 2026-03-22 12:47:16 +08:00
143 lines
3.6 KiB
JavaScript
143 lines
3.6 KiB
JavaScript
const path = require('path');
|
|
const CleanWebpackPlugin = require('clean-webpack-plugin');
|
|
const autoprefixer = require('autoprefixer');
|
|
const HtmlWebPackPlugin = require('html-webpack-plugin');
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); // MINI CSS
|
|
const CSSSplitWebpackPlugin = require('css-split-webpack-plugin').default;
|
|
function assetsPath(_path) {
|
|
return path.posix.join('static', _path);
|
|
}
|
|
|
|
const config = {
|
|
context: path.resolve(),
|
|
resolve: {
|
|
extensions: ['.js', '.json', '.jsx'],
|
|
alias: {
|
|
'@': path.resolve('./src')
|
|
}
|
|
},
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.(js|jsx)$/,
|
|
loader: 'eslint-loader',
|
|
enforce: 'pre',
|
|
include: [path.resolve('./src'), path.resolve('./test')],
|
|
options: {
|
|
formatter: require('eslint-friendly-formatter')
|
|
}
|
|
},
|
|
{
|
|
test: /\.(sa|sc|c)ss$/,
|
|
use: [
|
|
MiniCssExtractPlugin.loader,
|
|
'css-loader',
|
|
'sass-loader',
|
|
{
|
|
loader: 'postcss-loader',
|
|
options: {
|
|
ident: 'postcss',
|
|
plugins: () => [
|
|
require('postcss-flexbugs-fixes'),
|
|
autoprefixer({
|
|
browsers: [
|
|
'>1%',
|
|
'last 4 versions',
|
|
'Firefox ESR',
|
|
'not ie < 9' // React doesn't support IE8 anyway
|
|
],
|
|
flexbox: 'no-2009'
|
|
})
|
|
]
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
test: /\.less$/,
|
|
use: [{
|
|
loader: 'style-loader',
|
|
}, {
|
|
loader: 'css-loader', // translates CSS into CommonJS
|
|
}, {
|
|
loader: 'less-loader', // compiles Less to CSS
|
|
options: {
|
|
javascriptEnabled: true,
|
|
},
|
|
}],
|
|
},
|
|
{
|
|
test: /\.js|jsx$/,
|
|
exclude: /node_modules/,
|
|
loader: 'babel-loader',
|
|
options: {
|
|
presets: ['@babel/env', '@babel/preset-react'],
|
|
plugins: [
|
|
['@babel/plugin-proposal-decorators', { legacy: true }],
|
|
['@babel/plugin-proposal-class-properties', { loose: true }],
|
|
"@babel/plugin-proposal-export-default-from"
|
|
]
|
|
}
|
|
},
|
|
{
|
|
test: /\.html$/,
|
|
use: [
|
|
{
|
|
loader: 'html-loader',
|
|
options: { minimize: true }
|
|
}
|
|
]
|
|
},
|
|
{
|
|
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
|
|
loader: 'url-loader',
|
|
options: {
|
|
limit: 10000,
|
|
name: assetsPath('img/[name].[hash:7].[ext]')
|
|
}
|
|
},
|
|
{
|
|
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
|
|
loader: 'url-loader',
|
|
options: {
|
|
limit: 10000,
|
|
name: assetsPath('media/[name].[hash:7].[ext]')
|
|
}
|
|
},
|
|
{
|
|
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
|
loader: 'url-loader',
|
|
options: {
|
|
limit: 10000,
|
|
name: assetsPath('fonts/[name].[hash:7].[ext]')
|
|
}
|
|
}
|
|
]
|
|
},
|
|
plugins: [
|
|
new CleanWebpackPlugin(['dist', 'build'], {
|
|
root: path.resolve(),
|
|
verbose: true,
|
|
dry: false
|
|
}),
|
|
new CSSSplitWebpackPlugin({
|
|
size: 3000
|
|
})
|
|
],
|
|
// 生产
|
|
optimization: {
|
|
minimizer: [
|
|
new OptimizeCSSAssetsPlugin({
|
|
cssProcessor: require('cssnano')({
|
|
reduceIdents: false,
|
|
// 避免 cssnano 重新计算 z-index
|
|
safe: true
|
|
})
|
|
})
|
|
]
|
|
}
|
|
};
|
|
|
|
module.exports = config;
|