forked from mattgodbolt/jsbeeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
112 lines (106 loc) · 3.11 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"use strict";
import * as path from 'path';
import CopyWebpackPlugin from "copy-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import OptimizeCssAssetsPlugin from "optimize-css-assets-webpack-plugin";
import TerserPlugin from "terser-webpack-plugin";
import {CleanWebpackPlugin} from "clean-webpack-plugin";
import HtmlWebpackPlugin from 'html-webpack-plugin';
import {fileURLToPath} from 'url';
const __dirname = path.resolve(path.dirname(fileURLToPath(import.meta.url)));
const isDev = process.env.NODE_ENV !== "production";
const entry = path.resolve(__dirname, "./main.js");
const outputPath = path.resolve(__dirname, "out/dist");
function getOptimizationSettings() {
return {
minimize: !isDev,
minimizer: [
new OptimizeCssAssetsPlugin({
cssProcessorPluginOptions: {
preset: ["default", {discardComments: {removeAll: true}}],
},
}),
new TerserPlugin(),
],
};
}
function getPlugins() {
return [
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{
from: "roms/**/*",
globOptions: {ignore: ["**/*.txt", "**/*README*"]},
},
{
from: "discs/*.[ds]sd",
},
{
from: "tapes/*.uef",
},
{
from: "tapes/*.tape",
},
{
from: "sounds/**/*.wav",
},
],
}),
new MiniCssExtractPlugin({
filename: isDev ? "[name].css" : "[name].[contenthash].css",
}),
new HtmlWebpackPlugin({
title: "jsbeeb - Javascript BBC Micro emulator",
template: "index.html"
})
];
}
export default {
mode: isDev ? "development" : "production",
entry: entry,
target: "web",
// "fs" used in a couple of places to support node
externals: ["fs"],
output: {
filename: isDev ? "[name].js" : `[name].[contenthash].js`,
path: outputPath,
},
devtool: "source-map",
plugins: getPlugins(),
devServer: {
hot: isDev,
static: {
publicPath: "/",
directory: "./",
},
},
optimization: getOptimizationSettings(),
module: {
rules: [
{
test: /\.less$/,
use: [
isDev ? "style-loader" : {loader: MiniCssExtractPlugin.loader},
"css-loader",
"less-loader",
],
},
{
test: /\.css$/,
use: [
isDev ? "style-loader" : {loader: MiniCssExtractPlugin.loader},
"css-loader",
],
},
{
test: /\.(html)$/,
loader: "html-loader",
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset',
},
],
},
};