2019-01-15 19:36:09 +01:00
|
|
|
const path = require("path");
|
2019-02-06 19:08:31 +01:00
|
|
|
const os = require("os");
|
2019-01-15 19:36:09 +01:00
|
|
|
const environment = process.env.NODE_ENV || "development";
|
|
|
|
const HappyPack = require("happypack");
|
|
|
|
const webpack = require("webpack");
|
2019-04-03 21:24:00 +02:00
|
|
|
const TerserPlugin = require("terser-webpack-plugin");
|
2019-01-15 19:36:09 +01:00
|
|
|
|
|
|
|
const root = path.join(__dirname, "..");
|
|
|
|
|
2019-01-18 22:46:40 +01:00
|
|
|
module.exports = (options = {}) => ({
|
2019-01-15 19:36:09 +01:00
|
|
|
context: root,
|
2019-02-26 18:07:00 +01:00
|
|
|
devtool: "none",
|
2019-04-16 02:48:12 +02:00
|
|
|
externals: {
|
|
|
|
fsevents: "fsevents",
|
|
|
|
},
|
2019-04-18 00:18:20 +02:00
|
|
|
output: {
|
|
|
|
path: path.join(options.dirname || __dirname, "out"),
|
|
|
|
chunkFilename: `${options.name || "general"}.[name].[hash:6].js`,
|
|
|
|
filename: `${options.name || "general"}.[name].[hash:6].js`
|
|
|
|
},
|
2019-01-15 19:36:09 +01:00
|
|
|
module: {
|
|
|
|
rules: [{
|
2019-02-04 21:03:59 +01:00
|
|
|
loader: "string-replace-loader",
|
|
|
|
test: /\.(j|t)s/,
|
|
|
|
options: {
|
|
|
|
multiple: [{
|
2019-04-19 20:31:34 +02:00
|
|
|
// These will be handled by file-loader. Must be a fully formed URI.
|
|
|
|
// The !! prefix causes it to ignore other loaders.
|
2019-02-04 21:03:59 +01:00
|
|
|
search: "require\\.toUrl\\(",
|
2019-04-19 20:31:34 +02:00
|
|
|
replace: `${
|
|
|
|
options.node
|
|
|
|
? "'file://'"
|
|
|
|
: "location.protocol + '//' + location.host + location.pathname.replace(/\\/$/,'')"
|
|
|
|
} + '/' + require('!!file-loader?name=[path][name].[ext]!' + `,
|
2019-02-04 21:03:59 +01:00
|
|
|
flags: "g",
|
|
|
|
}, {
|
|
|
|
search: "require\\.__\\$__nodeRequire",
|
|
|
|
replace: "require",
|
|
|
|
flags: "g",
|
|
|
|
}, {
|
|
|
|
search: "\\.attributes\\[([^\\]]+)\\] = ([^;]+)",
|
|
|
|
replace: ".setAttribute($1, $2)",
|
|
|
|
flags: "g",
|
|
|
|
}],
|
|
|
|
},
|
2019-01-15 19:36:09 +01:00
|
|
|
}, {
|
|
|
|
test: /\.node$/,
|
|
|
|
use: "node-loader",
|
|
|
|
}, {
|
|
|
|
use: [{
|
|
|
|
loader: "happypack/loader?id=ts",
|
|
|
|
}],
|
|
|
|
test: /(^.?|\.[^d]|[^.]d|[^.][^d])\.tsx?$/,
|
|
|
|
}, {
|
|
|
|
test: /\.wasm$/,
|
|
|
|
type: "javascript/auto",
|
2019-02-25 18:49:09 +01:00
|
|
|
}],
|
2019-01-15 19:36:09 +01:00
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
"@coder": path.join(root, "packages"),
|
|
|
|
},
|
|
|
|
extensions: [".js", ".jsx", ".ts", ".tsx", ".json", ".css"],
|
|
|
|
mainFiles: [
|
|
|
|
"index",
|
|
|
|
"src/index",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
resolveLoader: {
|
|
|
|
modules: [
|
|
|
|
path.join(root, "node_modules"),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new HappyPack({
|
|
|
|
id: "ts",
|
2019-03-06 00:02:49 +01:00
|
|
|
threads: Math.max(os.cpus().length - 1, 1),
|
2019-01-15 19:36:09 +01:00
|
|
|
loaders: [{
|
2019-04-03 21:24:00 +02:00
|
|
|
path: "cache-loader",
|
|
|
|
query: {
|
|
|
|
cacheDirectory: path.join(__dirname, "..", ".cache"),
|
|
|
|
},
|
|
|
|
}, {
|
2019-01-15 19:36:09 +01:00
|
|
|
path: "ts-loader",
|
|
|
|
query: {
|
|
|
|
happyPackMode: true,
|
2019-01-18 22:46:40 +01:00
|
|
|
compilerOptions: options.typescriptCompilerOptions,
|
2019-01-15 19:36:09 +01:00
|
|
|
},
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
"process.env.NODE_ENV": `"${environment}"`,
|
2019-01-22 21:41:44 +01:00
|
|
|
"process.env.LOG_LEVEL": `"${process.env.LOG_LEVEL || ""}"`,
|
2019-03-01 22:51:11 +01:00
|
|
|
"process.env.SERVICE_URL": `"${process.env.SERVICE_URL || ""}"`,
|
2019-03-07 01:15:52 +01:00
|
|
|
"process.env.VERSION": `"${process.env.VERSION || ""}"`,
|
2019-01-15 19:36:09 +01:00
|
|
|
}),
|
|
|
|
],
|
2019-04-03 21:24:00 +02:00
|
|
|
optimization: {
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin({
|
|
|
|
cache: path.join(__dirname, "..", ".cache", "terser"),
|
|
|
|
parallel: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
2019-01-15 19:36:09 +01:00
|
|
|
stats: {
|
|
|
|
all: false, // Fallback for options not defined.
|
|
|
|
errors: true,
|
|
|
|
warnings: true,
|
|
|
|
},
|
2019-01-18 22:46:40 +01:00
|
|
|
});
|