forked from damoclis/dmcscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
84 lines (80 loc) · 2.15 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
const path = require("path");
const fs = require("fs");
const webpack = require("webpack");
// Build the C-like library
const lib = {
entry: [ "./src/glue/js", "./src/index.ts" ],
module: {
rules: [
{
test: /\.ts$/,
use: "ts-loader",
exclude: /node_modules/
}
]
},
externals: [ "binaryen" ],
resolve: {
extensions: [ ".ts", ".js" ]
},
output: {
filename: "assemblyscript.js",
path: path.resolve(__dirname, "dist"),
library: "assemblyscript",
libraryTarget: "umd",
globalObject: "typeof self !== 'undefined' ? self : this"
},
devtool: "source-map",
performance: {
hints : false
}
};
// Build asc for browser usage
const bin = {
context: path.join(__dirname, "cli"),
entry: [ "./asc.js" ],
externals: [{
"../dist/assemblyscript.js": "assemblyscript"
}],
node: {
"buffer": false,
"fs": "empty",
"global": true,
"os": false,
"process": "mock",
"crypto": false
},
output: {
filename: "asc.js",
path: path.resolve(__dirname, "dist"),
library: "asc",
libraryTarget: "umd",
globalObject: "typeof self !== 'undefined' ? self : this"
},
devtool: "source-map",
performance: {
hints : false
},
plugins: [
new webpack.DefinePlugin({
BUNDLE_VERSION: JSON.stringify(require("./package.json").version),
BUNDLE_LIBRARY: (() => {
const libDir = path.join(__dirname, "std", "assembly");
const libFiles = require("glob").sync("**/!(*.d).ts", { cwd: libDir });
const lib = {};
libFiles.forEach(file => lib[file.replace(/\.ts$/, "")] = bundleFile(path.join(libDir, file)));
return lib;
})(),
BUNDLE_DEFINITIONS: {
"assembly": bundleFile(path.join(__dirname, "std", "assembly", "index.d.ts")),
"portable": bundleFile(path.join(__dirname, "std", "portable", "index.d.ts"))
},
__dirname: JSON.stringify(".")
}),
new webpack.IgnorePlugin(/\.\/src|package\.json|^(ts\-node|glob)$/)
]
};
function bundleFile(filename) {
return JSON.stringify(fs.readFileSync(filename, { encoding: "utf8" }).replace(/\r\n/g, "\n"));
}
module.exports = [ lib, bin ];