generated from lloydevans/tiny-webpack-typescript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
83 lines (72 loc) · 1.59 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
const pkg = require("./package.json");
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = (env = {}) => {
env = {
...{
prod: false,
modern: true,
editor: false,
},
...env,
};
/** @type {import("webpack").Configuration} */
let config = {
entry: env.editor ? "./src/index-editor.ts" : "./src/index.ts",
devtool: "source-map",
stats: {
assets: false,
},
devServer: {
host: "0.0.0.0",
port: 3000,
hot: false,
open: false,
compress: true,
},
output: {
filename: "bundle.js",
path: path.join(__dirname, "build"),
},
module: {
rules: [
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
{
test: /\.tsx?$/,
loader: "ts-loader",
options: {
compilerOptions: {
target: env.modern ? "ES2019" : "ES5",
},
},
},
{
test: require.resolve("tweenjs/lib/tweenjs"),
use: "imports-loader?wrapper=window",
},
{
test: require.resolve("./libs/tween-group.js"),
use: "imports-loader?wrapper=window",
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js", ".css"],
},
plugins: [
new HtmlWebpackPlugin({ template: "src/index.html", hash: true }),
new CopyWebpackPlugin({ patterns: [{ from: "static" }] }),
new webpack.DefinePlugin({
ENV_VERSION: JSON.stringify(pkg.version),
ENV_PROD: JSON.stringify(!!env.prod),
}),
],
mode: env.prod ? "production" : "development",
};
return config;
};