Files
ic10emu/www/webpack.config.prod.js
2024-03-29 15:13:46 -07:00

128 lines
3.5 KiB
JavaScript

const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const miniCssExtractPlugin = require('mini-css-extract-plugin');
const ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");
const path = require('path');
module.exports = {
entry: "./src/js/main.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "main.js",
},
devServer: {
static: path.resolve(__dirname, 'dist'),
port: 8080,
hot: true
},
mode: "production",
devtool: "source-map",
plugins: [
new CopyWebpackPlugin({ patterns: ['img/*.png', 'img/*/*.png'] }),
new HtmlWebpackPlugin({ template: './src/index.html' }),
new miniCssExtractPlugin()
],
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.(jpg|png|svg|gif)$/,
type: 'asset/resource',
},
{
test: /\.(scss)$/,
use: [{
// inject CSS to page
loader: miniCssExtractPlugin.loader
}, {
// translates CSS into CommonJS modules
loader: 'css-loader'
}, {
// Run postcss actions
loader: 'postcss-loader',
options: {
// `postcssOptions` is needed for postcss 8.x;
// if you use postcss 7.x skip the key
postcssOptions: {
// postcss plugins, can be exported to postcss.config.js
plugins: function () {
return [
require('autoprefixer')
];
}
}
}
}, {
// compiles Sass to CSS
loader: 'sass-loader'
}],
// parser: {
// javascript : { importMeta: false }
// }
},],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
fallback: {
"crypto": require.resolve("crypto-browserify"),
"buffer": require.resolve("buffer"),
"stream": require.resolve("stream-browserify"),
"vm": require.resolve("vm-browserify"),
},
},
experiments: {
asyncWebAssembly: true,
syncWebAssembly: true,
},
optimization: {
minimizer: [
new ImageMinimizerPlugin({
minimizer: {
implementation: ImageMinimizerPlugin.imageminMinify,
options: {
// Lossless optimization with custom option
// Feel free to experiment with options for better result for you
plugins: [
["gifsicle", { interlaced: true }],
["jpegtran", { progressive: true }],
["optipng", { optimizationLevel: 5 }],
// Svgo configuration here https://github.com/svg/svgo#configuration
[
"svgo",
{
plugins: [
{
name: "preset-default",
params: {
overrides: {
removeViewBox: false,
addAttributesToSVGElement: {
params: {
attributes: [
{ xmlns: "http://www.w3.org/2000/svg" },
],
},
},
},
},
},
],
},
],
],
},
},
})
]
}
// output: {
// filename: 'bundle.js',
// path: path.resolve(__dirname, 'dist'),
// },
};