-
Notifications
You must be signed in to change notification settings - Fork 68
/
webpack.config.js
115 lines (109 loc) · 3.22 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
113
114
115
"use strict";
import * as path from "path";
import CopyWebpackPlugin from "copy-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import CssMinimizerPlugin from "css-minimizer-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 CssMinimizerPlugin(), 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",
},
{
from: "teletext/*.dat",
},
{
from: "music5000-worklet.js",
},
{
from: "econet/*.dat",
},
],
}),
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: "./",
watch: {
ignored: "**/.*",
},
},
},
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",
},
{
test: /\.js$/,
enforce: "pre",
use: ["source-map-loader"],
},
],
},
};