assemblyscript/webpack.config.js

85 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-02-09 15:43:57 +01:00
const path = require("path");
const fs = require("fs");
const webpack = require("webpack");
2017-12-05 13:35:14 +01:00
2018-02-10 01:09:34 +01:00
// Build the C-like library
2018-02-09 15:43:57 +01:00
const lib = {
entry: [ "./src/glue/js", "./src/index.ts" ],
2017-12-05 13:35:14 +01:00
module: {
rules: [
{
test: /\.ts$/,
use: "ts-loader",
exclude: /node_modules/
}
]
},
2018-02-09 15:43:57 +01:00
externals: [ "binaryen" ],
2017-12-05 13:35:14 +01:00
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
}
2018-02-09 15:43:57 +01:00
};
// Build asc for browser usage
const bin = {
2018-05-28 18:55:51 +02:00
context: path.join(__dirname, "cli"),
2018-02-09 15:43:57 +01:00
entry: [ "./asc.js" ],
externals: [{
"../dist/assemblyscript.js": "assemblyscript"
2018-02-10 01:09:34 +01:00
}],
2018-02-09 15:43:57 +01:00
node: {
"buffer": false,
2018-02-09 15:43:57 +01:00
"fs": "empty",
"global": true,
"os": false,
2018-02-09 15:43:57 +01:00
"process": "mock",
"crypto": false
2018-02-09 15:43:57 +01:00
},
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
},
2018-02-09 15:43:57 +01:00
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 });
2018-02-09 15:43:57 +01:00
const lib = {};
2018-04-03 23:56:48 +02:00
libFiles.forEach(file => lib[file.replace(/\.ts$/, "")] = bundleFile(path.join(libDir, file)));
2018-02-09 15:43:57 +01:00
return lib;
})(),
2018-02-10 17:25:31 +01:00
BUNDLE_DEFINITIONS: {
"assembly": bundleFile(path.join(__dirname, "std", "assembly", "index.d.ts")),
"portable": bundleFile(path.join(__dirname, "std", "portable", "index.d.ts"))
2018-02-10 17:25:31 +01:00
},
2018-02-09 15:43:57 +01:00
__dirname: JSON.stringify(".")
}),
new webpack.IgnorePlugin(/\.\/src|package\.json|^(ts\-node|glob)$/)
2018-02-09 15:43:57 +01:00
]
};
2018-02-10 17:25:31 +01:00
function bundleFile(filename) {
return JSON.stringify(fs.readFileSync(filename, { encoding: "utf8" }).replace(/\r\n/g, "\n"));
}
2018-02-09 15:43:57 +01:00
module.exports = [ lib, bin ];