chore: Use webpack to build production version
This commit is contained in:
48
webpack.config.js
Normal file
48
webpack.config.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const path = require('path');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
||||
|
||||
module.exports = (env, argv) => {
|
||||
const isProd = argv.mode === 'production';
|
||||
|
||||
return {
|
||||
entry: './fabula-ultima-sheet.js',
|
||||
output: {
|
||||
filename: isProd ? 'bundle.[contenthash].js' : 'bundle.js',
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
clean: true,
|
||||
// Disable IIFE wrapping so onclick= handlers can reach global functions
|
||||
iife: false,
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
isProd ? MiniCssExtractPlugin.loader : 'style-loader',
|
||||
'css-loader',
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
...(isProd
|
||||
? [new MiniCssExtractPlugin({ filename: 'styles.[contenthash].css' })]
|
||||
: []),
|
||||
new HtmlWebpackPlugin({
|
||||
template: './fabula-ultima-sheet.html',
|
||||
filename: 'index.html',
|
||||
scriptLoading: 'blocking',
|
||||
}),
|
||||
],
|
||||
optimization: {
|
||||
minimizer: ['...', new CssMinimizerPlugin()],
|
||||
},
|
||||
devServer: {
|
||||
static: { directory: path.resolve(__dirname, 'dist') },
|
||||
port: 8080,
|
||||
open: true,
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user