-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.build.js
114 lines (104 loc) · 3.53 KB
/
webpack.build.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
/* eslint-env node */
const path = require("path");
const webpack = require("webpack");
const PRODUCTION = process.env.NODE_ENV === "production";
const TARGET_FOLDER = PRODUCTION ? "dist" : "build";
const TerserPlugin = require("terser-webpack-plugin");
const config = {
mode: PRODUCTION ? "production" : "development",
entry: {
editron: path.join(__dirname, "editron.ts")
},
output: {
filename: "[name].js",
library: ["editron"],
path: path.resolve(__dirname, TARGET_FOLDER)
},
context: __dirname,
target: "web",
devtool: PRODUCTION ? false : "source-map",
externals: {
mithril: "m"
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
modules: [".", "node_modules"],
alias: {
nanoevents: path.resolve("./node_modules/nanoevents/index.js"),
"medium-editor-styles": path.resolve("./node_modules/medium-editor/dist/css/medium-editor.min.css"),
"medium-editor-theme": path.resolve("./node_modules/medium-editor/dist/css/themes/flat.min.css"),
"json-schema-library": path.resolve("./node_modules/json-schema-library")
}
},
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: "ts-loader",
options: {
configFile: path.resolve(__dirname, "tsconfig.json"),
compilerOptions: {
sourceMap: !PRODUCTION
}
}
}
},
{
test: /.*.js$/,
loader: require.resolve("babel-loader"),
include: [
path.resolve(__dirname, "app"),
path.resolve(__dirname, "lib"),
/json-.*\//, /editron.*\//
],
exclude: /node_modules/,
options: {
presets: [
[
"@babel/preset-env",
{
useBuiltIns: 'usage',
corejs: 3
}
]
],
plugins: [
"@babel/plugin-transform-runtime",
"@babel/plugin-transform-object-assign",
"@babel/plugin-proposal-object-rest-spread"
]
}
},
{
test: /.*.html$/,
loaders: [
"file-loader?name=index.html",
"extract-loader",
"html-loader"
],
// include: [path.join(__dirname, "test", "support", "local-setup.html")]
}
]
},
optimization: {
minimizer: [].concat(PRODUCTION ? [
new TerserPlugin()
// new (require("uglifyjs-webpack-plugin"))({
// sourceMap: false,
// uglifyOptions: {
// compress: { drop_console: true } // eslint-disable-line @typescript-eslint/camelcase
// }
// })
] : [])
},
plugins: [
new webpack.DefinePlugin({ DEBUG: !PRODUCTION }),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require(path.join(__dirname, TARGET_FOLDER, "manifest.json")),
sourceType: "var"
})
]
};
module.exports = config;