-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
166 lines (152 loc) · 4.73 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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
const path = require("path");
const webpack = require("webpack");
// const HtmlWebpackPlugin = require("html-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const project = require("./project.config");
const inProject = path.resolve.bind(path, project.basePath);
const inProjectSrc = (file) => inProject(project.srcDir, file);
const __DEV__ = project.env === "development";
const __PROD__ = project.env === "production";
const config = {
mode: project.env,
entry: {},
output: {
path: inProject(project.outDir),
publicPath: project.publicPath,
filename: "[name].js",
libraryTarget: "commonjs2"
},
resolve: {
modules: [
inProject(project.srcDir),
inProject("scripts"),
"node_modules"
],
extensions: [".js", ".jsx", ".json"]
},
module: {
rules: [
{test: inProject("scripts/ink-engine"), use: [{loader: "ignore-loader"}]},
{test: /\.html$/, use: {loader: "html-loader"}},
{test: /\.css$/, use: ExtractTextPlugin.extract({fallback: "style-loader", use: [{loader: "css-loader", options: {sourceMap: true, url: false}}]})},
{test: /\.(png|svg|jpg|gif)$/, use: [{loader: "file-loader", options: {name: "[path][name].[ext]", publicPath: `${__dirname}/dist/`}}]},
{
test: /\.jsx?$/,
exclude: [
inProject("node_modules"),
inProject("scripts"),
inProject("scripts/ink-engine/Module.js"),
inProject("scripts/ink-engine/WacomInkEngine.js"),
inProject("connectivity/bridge/bridge.js"),
inProject("connectivity/bridge/wacom.smartPadCommunication.js"),
],
use: {
// babel-core babel-loader
loader: "babel-loader",
options: {
// babel-preset-env babel-preset-stage-0 babel-preset-react
// babel-preset-es2015-without-strict
presets: ["@babel/preset-env", "@babel/preset-react"],
// babel-plugin-transform-remove-strict-mode // babel-plugin-add-module-exports, babel-plugin-transform-runtime, babel-plugin-transform-es2015-modules-commonjs
plugins: [
// Stage 0
"@babel/plugin-proposal-function-bind",
// Stage 1
"@babel/plugin-proposal-export-default-from",
"@babel/plugin-proposal-logical-assignment-operators",
["@babel/plugin-proposal-optional-chaining", { loose: false }],
["@babel/plugin-proposal-pipeline-operator", { proposal: "minimal" }],
["@babel/plugin-proposal-nullish-coalescing-operator", { loose: false }],
"@babel/plugin-proposal-do-expressions",
// Stage 2
["@babel/plugin-proposal-decorators", { legacy: true }],
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-throw-expressions",
// Stage 3
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
["@babel/plugin-proposal-class-properties", { loose: false }],
"@babel/plugin-proposal-json-strings",
"transform-remove-strict-mode", [
"inline-react-svg", {
"svgo": {
"plugins": [
{"convertShapeToPath": false}
]
}
}]
]
}
}
}
]
},
plugins: [
new CleanWebpackPlugin(["dist"]),
new ExtractTextPlugin({filename: "bundle.css", disable: false, allChunks: true}),
new webpack.IgnorePlugin(new RegExp("^(ipc)$")),
new webpack.DefinePlugin(Object.assign({
"process.env": { NODE_ENV: JSON.stringify(project.env) },
__DEV__,
__PROD__
}, project.globals))
],
optimization: {
runtimeChunk: "single",
minimize: __PROD__,
minimizer: [],
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: "vendor",
chunks: "all"
}
}
}
},
externals: project.externals
}
if (project.target == "ELECTRON") {
config.entry.main = inProjectSrc("index");
config.target = "electron-renderer";
if (__DEV__) {
config.plugins.push(new webpack.SourceMapDevToolPlugin({
filename: "[name].js.map",
exclude: ["vendor.js"]
}));
}
}
else if (project.target == "UWP")
config.entry.main = inProjectSrc("index-uwp");
// config.plugins.push(new HtmlWebpackPlugin({template: inProject("index.html"), inject: true}));
if (__PROD__) {
/*
config.optimization.minimizer.push(
new UglifyJSPlugin({
sourceMap: !!config.devtool,
uglifyOptions: {
sourceMap: !!config.devtool,
comments: false,
compress: {
warnings: false,
screw_ie8: true,
conditionals: true,
unused: true,
comparisons: true,
sequences: true,
dead_code: true,
evaluate: true,
if_return: true,
join_vars: true
}
}
})
);
*/
}
module.exports = config