-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
webpack.config.js
63 lines (59 loc) · 1.84 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
const exec = require("child_process").exec;
let isProd = false;
let isWatch = true;
try {
const config = JSON.parse(process.env.npm_config_argv);
isProd = config.original.includes("--production");
isWatch = !(config.original.includes("--no-watch") || isProd);
} catch (e) { }
module.exports = {
entry: "./src/ui/main.tsx",
mode: isProd ? "production" : "development",
watch: isWatch,
output: {
path: __dirname + "/dist",
filename: 'main.js',
libraryTarget: "commonjs2"
},
devtool: isProd ? "none" : "source-map",
resolve: { extensions: ['.tsx', '.ts', '.jsx', '.js'] },
module: {
rules: [
// Converts TypeScript code to JavaScript
{ test: /\.tsx?$/, use: 'ts-loader', exclude: /node_modules/ },
// Enables including CSS by doing "import './file.css'" in your TypeScript code
{ test: /\.css$/, loader: [{ loader: 'style-loader' }, { loader: 'css-loader' }] },
// Allows you to use "<%= require('./file.svg') %>" in your HTML code to get a data URI
{ test: /\.(png|jpg|gif|webp|svg|zip)$/, loader: [{ loader: 'url-loader' }] },
]
},
externals: [
"os",
"scenegraph",
"application",
"clipboard",
"assets",
"uxp",
function (context, request, callback) {
if (/lib/.test(request)) {
return callback(null, request.substr(1), "commonjs2")
}
callback();
}
],
plugins: [
{
apply: (compiler) => {
const runDeploy = () => exec("yarn deploy", (err, stdout, stderr) => {
if (stdout) { console.log("\nWebpack bundle complete, plugin folder updated"); }
if (stderr) { console.error(stderr); }
});
if (isWatch) {
compiler.hooks.afterEmit.tap("DeployPlugin", runDeploy);
} else {
compiler.hooks.done.tap("DeployPlugin", runDeploy);
}
}
}
]
};