-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
105 lines (100 loc) · 3.57 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
const webpack = require("webpack");
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
// const webpackRxjsExternals = require('webpack-rxjs-externals');
const webpackGoodcoreExternals = require('goodcore/webpackExternals');
const HappyPack = require('happypack');
const path = require("path");
const chalk = require("chalk");
const package = require("./package.json");
const dependencies = Object.keys(package.dependencies);
const isProd = (arg) => (arg || "").match("^p|prod|production$");
const isWatch = (arg) => (arg || "").match("^w|watch$") !== null;
// const isTest = (arg) => (arg || "").match("^t|test$") !== null;
// const isTestWatch = (arg) => (arg || "").match("^tw|testwatch$") !== null;
var libEntries = {};
libEntries[package.name] = "./src/lib/index.ts";
module.exports = (envOptions) => {
envOptions = envOptions || {};
console.log(chalk.green("arguments: " + JSON.stringify(envOptions)));
console.log(chalk.blueBright("Environment: " + (isProd(envOptions.MODE) ? "production" : "development")));
console.log(chalk.blueBright("To change mode write --env.MODE=<production|development>"));
const source = path.resolve(__dirname, ".");
const destination = path.resolve(__dirname, "dist/lib");
console.log(chalk.blue(`source: ${source} \tdestination: ${destination}`));
const config = {
mode: isProd(envOptions.MODE) ? "production" : "development",
target: "web",
entry: libEntries,
externals: [
// webpackRxjsExternals(),
webpackGoodcoreExternals(),
// other externals here
],
// context: source,
output: {
path: destination,
filename: "[name].bundle.js",
chunkFilename: "[name].chunk.js",
library: "[name]",
libraryTarget: "umd"
},
resolve: {
extensions: [".ts", ".js", ".html"],
},
node: {
process: false
},
module: {
rules: [
{
test: /\.jsx?|\.tsx?$/,
use: 'happypack/loader',
},
{
test: /\.html|\.css|\.scss$/,
loader: "raw-loader"
},
]
},
plugins: [
new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true }),
new HappyPack({
loaders: [
{
loader: 'ts-loader',
options: {
configFile: "tsconfig.app.json",
happyPackMode: true // IMPORTANT! use transpileOnly mode to speed-up compilation
}
},
// {
// loader: 'babel-loader',
// options: {
// presets: ['es2015']
// }
// }
]
})
]
};
if (isProd(envOptions.MODE)) {
config.module.rules = [
...config.module.rules,
...[
]];
} else {
let isWatchMode = isWatch(envOptions.MODE);
if (isWatchMode) {
console.log(chalk.blueBright("Listening in watch mode..."));
}
config.watch = isWatchMode,
// config.module.rules.push(
// {
// }
// );
// config.plugins.push();
config.devtool = "#source-map";
}
return config;
};