125 lines
3.1 KiB
JavaScript
125 lines
3.1 KiB
JavaScript
const path = require('path');
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
const BundleTracker = require('webpack-bundle-tracker');
|
|
|
|
module.exports = (env, argv) => {
|
|
const isProduction = argv.mode === 'production';
|
|
|
|
return {
|
|
entry: {
|
|
main: './assets/js/main.js',
|
|
htmx: './assets/js/htmx-config.js',
|
|
vendor: './assets/js/vendor.js'
|
|
},
|
|
|
|
output: {
|
|
path: path.resolve(__dirname, 'static/dist'),
|
|
filename: isProduction ? '[name].[contenthash].js' : '[name].js',
|
|
chunkFilename: isProduction ? '[name].[contenthash].chunk.js' : '[name].chunk.js',
|
|
clean: true,
|
|
publicPath: '/static/dist/',
|
|
},
|
|
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.js$/,
|
|
exclude: /node_modules/,
|
|
use: {
|
|
loader: 'babel-loader',
|
|
options: {
|
|
presets: ['@babel/preset-env']
|
|
}
|
|
}
|
|
},
|
|
{
|
|
test: /\.scss$/,
|
|
use: [
|
|
isProduction ? MiniCssExtractPlugin.loader : 'style-loader',
|
|
'css-loader',
|
|
'postcss-loader',
|
|
'sass-loader'
|
|
]
|
|
},
|
|
{
|
|
test: /\.css$/,
|
|
use: [
|
|
isProduction ? MiniCssExtractPlugin.loader : 'style-loader',
|
|
'css-loader',
|
|
'postcss-loader'
|
|
]
|
|
},
|
|
{
|
|
test: /\.(png|jpe?g|gif|svg|ico)$/i,
|
|
type: 'asset/resource',
|
|
generator: {
|
|
filename: 'images/[name].[hash][ext]'
|
|
}
|
|
},
|
|
{
|
|
test: /\.(woff|woff2|eot|ttf|otf)$/i,
|
|
type: 'asset/resource',
|
|
generator: {
|
|
filename: 'fonts/[name].[hash][ext]'
|
|
}
|
|
}
|
|
]
|
|
},
|
|
|
|
plugins: [
|
|
new BundleTracker({
|
|
path: __dirname,
|
|
filename: 'webpack-stats.json'
|
|
}),
|
|
new MiniCssExtractPlugin({
|
|
filename: isProduction ? '[name].[contenthash].css' : '[name].css',
|
|
chunkFilename: isProduction ? '[name].[contenthash].chunk.css' : '[name].chunk.css'
|
|
})
|
|
],
|
|
|
|
optimization: {
|
|
splitChunks: {
|
|
chunks: 'all',
|
|
cacheGroups: {
|
|
vendor: {
|
|
test: /[\\/]node_modules[\\/]/,
|
|
name: 'vendors',
|
|
chunks: 'all',
|
|
},
|
|
common: {
|
|
name: 'common',
|
|
minChunks: 2,
|
|
chunks: 'all',
|
|
enforce: true
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
resolve: {
|
|
extensions: ['.js', '.scss', '.css'],
|
|
alias: {
|
|
'@': path.resolve(__dirname, 'assets'),
|
|
'@js': path.resolve(__dirname, 'assets/js'),
|
|
'@scss': path.resolve(__dirname, 'assets/scss'),
|
|
'@img': path.resolve(__dirname, 'assets/images')
|
|
}
|
|
},
|
|
|
|
devServer: {
|
|
static: {
|
|
directory: path.join(__dirname, 'static'),
|
|
},
|
|
compress: true,
|
|
port: 3000,
|
|
hot: true,
|
|
headers: {
|
|
'Access-Control-Allow-Origin': '*',
|
|
},
|
|
allowedHosts: 'all'
|
|
},
|
|
|
|
devtool: isProduction ? 'source-map' : 'eval-source-map'
|
|
};
|
|
};
|