forked from vintharas/js13k-spaceshooter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
93 lines (90 loc) · 2.29 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
const path = require("path");
// injects bundles in html
const HtmlWebpackPlugin = require("html-webpack-plugin");
// cleans up dist folder
const CleanWebpackPlugin = require("clean-webpack-plugin");
// copy files to output directory
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = {
entry: {
//kontra: "./src/loadkontra.js",
main: "./src/index.ts"
},
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "dist")
},
module: {
rules: [
// game engine kontra.js
/*
// this is highly inefficient
// it embeds the script as a string
// no chance of optimizing it
{
test: /kontra\.js/,
use: ["script-loader"]
},
*/
// styles
// TODO: this is adding 10K to the bundle :O
// review if I want to have this
/* This adds non minified 10K in prod
// I'll inline the css manually in the resulting template
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
exclude: /node_modules/
},
*/
// typescript
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/
},
// loading kontra as a global script
// it relies on this being window
/*
{
test: require.resolve("./src/libs/kontra.min.js"),
use: "imports-loader?this=>window"
},
{
test: require.resolve("./src/libs/kontra.min.js"),
use: "exports-loader?kontra=this.kontra"
},
*/
// Actual sprites
// Using Piksel thus far to create sprites manually
// it saves stuff as PNG, that may not be super optimal
{
test: /\.(png|svg|jpg|gif)$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]"
}
}
]
}
]
},
resolve: {
extensions: [".tsx", ".ts", ".js", ".css"]
},
plugins: [
new CleanWebpackPlugin(["dist"]),
new HtmlWebpackPlugin({
title: "js13k-spaceshooter",
template: "src/index.html",
minify: {
collapseWhitespace: true,
minifyCSS: true,
removeComments: true
}
})
//CopyWebpackPlugin([{ from: "libs/kontra.min.js", to: "kontra.min.js" }])
]
};