forked from AdobeXD/xd-to-flutter-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
94 lines (92 loc) · 2.35 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
const exec = require("child_process").exec;
const CircularDependencyPlugin = require("circular-dependency-plugin");
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.jsx",
mode: isProd ? "production" : "development",
watch: isWatch,
output: {
path: __dirname + "/build",
filename: 'main.js',
libraryTarget: "commonjs2"
},
devtool: isProd ? "none" : "source-map",
resolve: {
extensions: ['.js', '.jsx', '.styl'],
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: "babel-loader",
options: {
plugins: [
["transform-react-jsx", {
"pragma": "h", // default pragma is React.createElement
"pragmaFrag": "Fragment", // default is React.Fragment
}]
]
}
},
{
test: /\.styl?$/,
use: [
{
loader: "style-loader" // creates style nodes from JS strings
},
{
loader: "css-loader" // translates CSS into CommonJS
},
{
loader: "stylus-loader" // compiles Stylus to CSS
}
]
},
{
test: /\.(png|svg|jpg|gif)$/,
loader: 'file-loader',
options: {
outputPath: 'images',
name: '[name].[ext]'
}
},
]
},
externals: [
"os",
"scenegraph",
"application",
"clipboard",
"assets",
"uxp",
function (context, request, callback) {
if (/lib/.test(request)) {
return callback(null, request.substr(1), "commonjs2")
}
callback();
}
],
plugins: [
// new CircularDependencyPlugin({ failOnError: true }),
{
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);
}
}
}
]
};