forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
133 lines (127 loc) · 3.29 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
const path = require("path");
const fs = require("fs");
const webpack = require("webpack");
const TerserPlugin = require('terser-webpack-plugin');
function preamble(name) {
return [
"/**",
" * @license",
" * " + name,
" * Copyright Daniel Wirtz / The AssemblyScript Authors.",
" * SPDX-License-Identifier: Apache-2.0",
" */"
].join("\n");
}
// Build the C-like library
const lib = {
mode: "production",
target: ["web", "es6"],
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
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
output: {
comments: false,
preamble: preamble("The AssemblyScript Compiler.")
}
},
parallel: true,
extractComments: false
})
],
}
};
// Build asc for browser usage
const shimDir = path.join(__dirname, "cli", "shim");
const bin = {
mode: "production",
target: ["web", "es6"],
context: path.join(__dirname, "cli"),
entry: [ "./asc.js" ],
externals: [
"binaryen",
"assemblyscript"
],
node: {
global: true
},
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(".")
}),
// Browser shims
new webpack.NormalModuleReplacementPlugin(/^path$/, path.join(shimDir, "path")),
new webpack.NormalModuleReplacementPlugin(/^process$/, path.join(shimDir, "process")),
new webpack.NormalModuleReplacementPlugin(/^fs$/, path.join(shimDir, "fs"))
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
output: {
comments: false,
preamble: preamble("The AssemblyScript Compiler Frontend.")
}
},
parallel: true,
extractComments: false
})
],
}
};
function bundleFile(filename) {
return JSON.stringify(fs.readFileSync(filename, { encoding: "utf8" }).replace(/\r\n/g, "\n"));
}
module.exports = [ lib, bin ];