mirror of
https://github.com/quantum5/correcthorsebatterystaple.git
synced 2025-04-24 02:01:57 -04:00
89 lines
2.2 KiB
JavaScript
89 lines
2.2 KiB
JavaScript
const path = require('path')
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
|
|
const TerserPlugin = require('terser-webpack-plugin')
|
|
|
|
const mode = process.env.NODE_ENV || 'development'
|
|
|
|
module.exports = {
|
|
optimization: {
|
|
minimizer: [
|
|
new TerserPlugin({
|
|
cache: true,
|
|
extractComments: true,
|
|
parallel: true,
|
|
sourceMap: true
|
|
}),
|
|
new OptimizeCSSAssetsPlugin({})
|
|
]
|
|
},
|
|
entry: [
|
|
'core-js/fn/array/from',
|
|
'core-js/fn/array/includes',
|
|
'./src/app.js'
|
|
],
|
|
mode: mode,
|
|
output: {
|
|
filename: '[name].[contenthash].js',
|
|
path: path.resolve(__dirname, 'dist')
|
|
},
|
|
plugins: [
|
|
new HtmlWebpackPlugin({
|
|
template: 'src/index.ejs',
|
|
minify: mode === 'production' ? {
|
|
collapseWhitespace: true,
|
|
removeComments: true,
|
|
removeRedundantAttributes: true,
|
|
removeScriptTypeAttributes: true,
|
|
removeStyleLinkTypeAttributes: true,
|
|
useShortDoctype: true
|
|
} : false
|
|
}),
|
|
new MiniCssExtractPlugin({
|
|
filename: '[name].[contenthash].css'
|
|
})
|
|
],
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.(scss)$/,
|
|
use: [
|
|
{
|
|
loader: mode === 'production' ? MiniCssExtractPlugin.loader : 'style-loader'
|
|
},
|
|
{
|
|
// Interprets `@import` and `url()` like `import/require()` and will resolve them
|
|
loader: 'css-loader'
|
|
},
|
|
{
|
|
// Loader for webpack to process CSS with PostCSS
|
|
loader: 'postcss-loader',
|
|
options: {
|
|
plugins: function () {
|
|
return [
|
|
require('autoprefixer')
|
|
]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
// Loads a SASS/SCSS file and compiles it to CSS
|
|
loader: 'sass-loader'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
test: /\.(png|jp(e*)g|svg)$/,
|
|
use: [{
|
|
loader: 'file-loader',
|
|
options: {
|
|
limit: 8000, // Convert images < 8kb to base64 strings
|
|
name: '[name].[hash].[ext]'
|
|
}
|
|
}]
|
|
}
|
|
]
|
|
}
|
|
}
|