-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
135 lines (126 loc) · 3.22 KB
/
webpack.common.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const path = require("path");
const HtmlPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
// const git = require("git-rev-sync");
// const ImageminPlugin = require("imagemin-webpack-plugin").default;
module.exports = {
// //context directory is src
// context: path.join(__dirname, "src"),
//entry file of the project,(relative to context)
entry: "./src/game.ts",
output: {
//distribution directory
path: path.resolve(__dirname, "dist"),
/**
* webpack will import the file for the index.html automatically,though the js file does not exist on disk.
* the js file will generated after webpack build the project, and the js will inserted at index.html automatically.
* [hash:8] means unique 8 digit hash generated everytime.
**/
filename: "game.[hash:8].js",
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "esbuild-loader",
options: {
loader: "ts",
target: "es2020",
},
// exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".ts", ".js"],
},
plugins: [
new CleanWebpackPlugin(),
//copy all src/assets to dist/assets
new CopyWebpackPlugin({
patterns: [
// Copy Booyah assets
{
from: path.resolve(
require.resolve("booyah/package.json"),
"../images"
),
to: "booyah/images",
},
{
from: path.resolve(
require.resolve("booyah/package.json"),
"../fonts"
),
to: "booyah/fonts",
},
// Copy CSS
{ from: "*.css" },
// Copy game assets
{
from: "images",
to: "images",
},
{
from: "fonts",
to: "fonts",
},
{
from: "json",
to: "json",
},
{
from: "audio",
to: "audio",
},
{
from: "levels",
to: "levels",
},
{
from: "video",
to: "video",
},
{
from: "references",
to: "references",
},
],
}),
// //opimize all image file
// new ImageminPlugin({
// test: /\.(jpe?g|png|gif|svg)$/i,
// // optipng: {
// // optimizationLevel: 4
// // },
// //this way seems better on mac.
// pngquant: {
// verbose: true,
// quality: "80-90",
// },
// }),
//copy html to dist and insert the js reference.
new HtmlPlugin({
filename: path.join(__dirname, "dist", "index.html"),
// favicon: "./images/hole.png",
template: "./index.html",
templateParameters: {
date: new Date(),
// commit: git.short(),
// branch: git.branch(),
},
}),
// // Copy "embed" version
// new HtmlPlugin({
// filename: path.join(__dirname, "dist", "embed.html"),
// favicon: "./images/hole.png",
// template: "./embed.html",
// templateParameters: {
// date: new Date(),
// commit: git.short(),
// branch: git.branch(),
// },
// }),
],
};