90 lines
2.3 KiB
JavaScript
90 lines
2.3 KiB
JavaScript
const webpack = require('webpack')
|
|
const path = require('path')
|
|
const merge = require('webpack-merge')
|
|
const commonConfig = require('./helpers/webpack.common.config')
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
|
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin')
|
|
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin')
|
|
const Dotenv = require('dotenv-webpack')
|
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
|
|
.BundleAnalyzerPlugin
|
|
|
|
module.exports = merge(commonConfig, {
|
|
mode: 'production',
|
|
devtool: 'inline-sourcemap',
|
|
output: {
|
|
path: path.resolve(__dirname, '../../build'),
|
|
filename: 'script.js'
|
|
},
|
|
|
|
optimization: {
|
|
minimizer: [
|
|
new UglifyJsPlugin({
|
|
cache: true,
|
|
parallel: true,
|
|
sourceMap: false
|
|
}),
|
|
new OptimizeCSSAssetsPlugin({})
|
|
],
|
|
splitChunks: {
|
|
cacheGroups: {
|
|
styles: {
|
|
name: 'styles',
|
|
test: /\.css$/,
|
|
chunks: 'all',
|
|
enforce: true
|
|
}
|
|
}
|
|
}
|
|
},
|
|
plugins: [
|
|
new Dotenv(),
|
|
new MiniCssExtractPlugin({
|
|
filename: '[name].css',
|
|
chunkFilename: '[id].css'
|
|
}),
|
|
new HtmlWebpackPlugin({
|
|
template: 'html/index.html',
|
|
alwaysWriteToDisk: true
|
|
}),
|
|
new ScriptExtHtmlWebpackPlugin({
|
|
defaultAttribute: 'async'
|
|
}),
|
|
new HtmlWebpackHarddiskPlugin(),
|
|
new webpack.DefinePlugin({
|
|
'process.env.NODE_ENV': JSON.stringify('production')
|
|
}),
|
|
new BundleAnalyzerPlugin({
|
|
analyzerMode: 'static',
|
|
reportFilename: 'report.html'
|
|
})
|
|
],
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.js$/,
|
|
exclude: [
|
|
/(node_modules|bower_components)/
|
|
],
|
|
loader: 'babel-loader',
|
|
options: {
|
|
presets: ['@babel/preset-env', '@babel/preset-react']
|
|
}
|
|
},
|
|
{
|
|
test: /\.scss$/,
|
|
use: [
|
|
MiniCssExtractPlugin.loader,
|
|
{ loader: 'css-loader', options: { importLoaders: 2 } },
|
|
'postcss-loader',
|
|
{ loader: 'sass-loader' }
|
|
]
|
|
}
|
|
]
|
|
},
|
|
target: 'web'
|
|
})
|