correcthorsebatterystaple/webpack.config.js

85 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

2023-07-21 22:50:04 -04:00
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
2023-07-21 22:50:04 -04:00
const mode = process.env.NODE_ENV || 'development';
2018-11-26 01:51:26 -05:00
module.exports = {
2018-11-26 23:26:23 -05:00
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
2023-07-21 22:50:04 -04:00
terserOptions: {
sourceMap: true,
},
2018-11-26 23:26:23 -05:00
}),
2023-07-21 22:50:04 -04:00
new CssMinimizerPlugin({}),
],
2018-11-26 23:26:23 -05:00
},
entry: [
'core-js/fn/array/from',
'core-js/fn/array/includes',
2023-07-21 22:50:04 -04:00
'./src/app.js',
],
mode: mode,
2018-11-26 01:51:26 -05:00
output: {
filename: '[name].[contenthash].js',
2023-07-21 22:50:04 -04:00
path: path.resolve(__dirname, 'dist'),
2018-11-26 01:51:26 -05:00
},
plugins: [
new HtmlWebpackPlugin({
template: 'src/index.ejs',
2018-11-26 23:26:23 -05:00
minify: mode === 'production' ? {
collapseWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
2023-07-21 22:50:04 -04:00
useShortDoctype: true,
} : false,
}),
new MiniCssExtractPlugin({
2023-07-21 22:50:04 -04:00
filename: '[name].[contenthash].css',
}),
2018-11-26 01:51:26 -05:00
],
module: {
rules: [
{
test: /\.(scss)$/,
use: [
{
2023-07-21 22:50:04 -04:00
loader: mode === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
2018-11-26 01:51:26 -05:00
},
{
// Interprets `@import` and `url()` like `import/require()` and will resolve them
2023-07-21 22:50:04 -04:00
loader: 'css-loader',
2018-11-26 01:51:26 -05:00
},
{
// Loader for webpack to process CSS with PostCSS
loader: 'postcss-loader',
options: {
2023-07-21 22:50:04 -04:00
postcssOptions: {
plugins: function () {
return [
require('autoprefixer'),
];
},
},
},
2018-11-26 01:51:26 -05:00
},
{
// Loads a SASS/SCSS file and compiles it to CSS
2023-07-21 22:50:04 -04:00
loader: 'sass-loader',
},
],
},
{
test: /\.(png|jp(e*)g|svg)$/,
2023-07-21 22:50:04 -04:00
type: 'asset/resource',
},
],
},
};