This repository has been archived by the owner on Nov 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
151 lines (141 loc) · 4.14 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* global __dirname */
"use strict";
const path = require("path");
const webpack = require("webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const sourceDir = "./build/aot/";
const commonExternals = {};
["jquery", "bootstrap", "dexie",
// The mode service needs to load this dynamically.,
"wed/mode-map"]
.forEach((name) => {
commonExternals[name] = name;
});
const mainBundleExternals = { ...commonExternals };
// This needs to be loaded by the kitchen sink.
["dashboard/store"].forEach((name) => {
mainBundleExternals[name] = name;
});
function createMakeExternals(mapping) {
return function makeExternals(context, request, callback) {
// If the request is relative to the module it is in, we want to turn it
// into something relative to our sourceDir. This allows handling a request
// to "./store" made in a module located in "dashboard/" the same as a
// request to "dashboard/store" made from outside dashboard.
if (request[0] === ".") {
request = path.relative(sourceDir, path.join(context, request));
}
if (request in mapping) {
callback(null, mapping[request]);
return;
}
callback();
};
}
const common = {
context: __dirname,
devtool: "source-map",
output: {
path: path.join(__dirname, "build/prod/lib/"),
filename: "[name].js",
chunkFilename: "[id].chunk.js",
// This is a bit strange but it works. The chunks are put in build/prod/lib,
// but the page to load is in build/prod/lib/dashboard. By default the
// chunks are loaded relative to the page, and without a path prefix so the
// browser would look for them in build/prod/lib/dashboard. With "../" it
// looks one directory up.
publicPath: "../",
sourceMapFilename: "[name].map.js",
libraryTarget: "amd",
},
};
module.exports = [{
...common,
mode: "production",
resolve: {
modules: [sourceDir, "node_modules"],
extensions: [".ts", ".tsx", ".js", ".jsx"],
},
entry: {
// We make production.js the first entry so that anything production
// bootstrapping is done first.
dashboard: ["production.js", "dashboard-aot.js"],
},
module: {
rules: [{
test: /^.*\.js$/,
loader: "ng-router-loader",
options: {
// Must be true to avoid using the compiler at runtime.
aot: true,
// Do we need this??
bySymbol: false,
},
}, {
test: /\.(html|css)$/,
loader: "raw-loader",
}],
},
externals: createMakeExternals(mainBundleExternals),
plugins: [
new CopyWebpackPlugin([{
from: {
glob: "dashboard/index.html",
},
context: "build/dev/lib",
transform: content =>
content.toString()
// Remove the script that sets environment to development.
.replace(
/<script data-script-type="set-environment"[^]*?>[^]*?<\/script>/,
""),
}, ...["{kitchen-sink,global-config,wed-store,system.config,\
requirejs-local-config}.js",
"*.html"].map(x => ({
from: {
glob: x,
},
context: "build/dev/lib",
}))]),
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)@angular/,
path.join(__dirname, "./src")),
//
// The way our code is currently laid out. It is not useful to use
// this plugin. Reassess if the code is significantly changed.
//
// new webpack.optimize.CommonsChunkPlugin({
// name: "commons",
// }),
],
}, {
...common,
mode: "production",
resolve: {
modules: ["src", "node_modules"],
extensions: [".ts", ".tsx", ".js", ".jsx"],
},
entry: {
"dashboard/store": "dashboard/store.ts",
},
module: {
rules: [{
use: [{
loader: "ts-loader",
options: {
transpileOnly: true,
happyPackMode: true,
configFile: "src/tsconfig.json",
compilerOptions: {
module: "commonjs",
},
},
}],
}, {
test: /\.(html|css)$/,
loader: "raw-loader",
}],
},
externals: createMakeExternals(commonExternals),
}];