-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
88 lines (87 loc) · 2.9 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
const path = require("path");
module.exports = (env) => {
let entry = {};
// target component doesn't support debug mode because of a bug in webpack
// both entry points can't be combined because component needs experiments.outputModule, which kills build for browser
if (env["component"])
// when using react components and bundler
entry = {
component_compare_view: {
import: "./src/component/compare_view.tsx",
library: {
type: "module",
},
},
}
else
// when directly importing from browser without bundler
entry = {
browser_compare_view: {
import: "./src/browser/compare_view.ts",
// allow browser to access exposed functions
library: {
name: "compare_view",
type: "var",
},
},
drag_drop: {
import: "./src/drag_drop/drag_drop.ts",
// allow browser to access exposed functions
library: {
name: "drag_drop",
type: "var",
},
},
}
return {
// can be development or production
mode: env["production"] ? "production" : "development",
// eval good for development
devtool: env["production"] ? false : "eval-source-map",
// only entry file, include any imported files
entry: entry,
// react is already present in component using code
externals: {
"react": "react",
},
module: {
rules: [
{
// when test passed
test: /\.tsx?$/,
// use ts-loader to compile
use: "ts-loader",
include: [path.resolve(__dirname, "src")],
},
],
},
resolve: {
extensions: [".ts", ".js", ".tsx", ".jsx"],
},
output: {
// tell dev server where to serve code in memory from
publicPath: "public/dist",
// template based on keys in entry
filename: "[name].js",
// need absolute outputpath
path: path.resolve(__dirname, "public/dist"),
},
devServer: {
static: {
// load uncompiled files (e.g. html files) from public dir
directory: path.resolve(__dirname, "public"),
// where to serve them from
publicPath: "/",
},
devMiddleware: {
// where to serve compiled files from
publicPath: "/dist",
},
hot: true,
},
experiments: {
// only needed to compile component
outputModule: env["component"],
},
};
};