-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.server.config.js
68 lines (66 loc) · 2.27 KB
/
webpack.server.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
// Work around for https://github.com/angular/angular-cli/issues/7200
const path = require("path");
const webpack = require("webpack");
module.exports = {
target: "node",
mode: "none",
entry: {
express: "./src/server/express.ts"
},
externals: {
"./dist/server/main": 'require("./main")',
sharp: "commonjs sharp" //https://github.com/lovell/sharp/issues/794#issuecomment-306555683
},
//https://github.com/googleapis/gax-nodejs/issues/719#issuecomment-605250814
resolve: {
extensions: [".ts", ".js", ".json"],
alias: { pkg: path.resolve(__dirname, "./packages") }
},
optimization: {
minimize: false
},
output: {
// Puts the output at the root of the dist folder
path: path.join(__dirname, "dist/server"), //todo: `dist/${this.mode}`
filename: "[name].js", //'[name]' = entry[$key]
library: "",
libraryTarget: "commonjs-module"
//fix: setting library & libraryTarget to fix issue: require('./server.js') == undefined
//https://github.com/webpack/webpack/issues/2030#issuecomment-232886608
//https://github.com/webpack/webpack/issues/2030#issuecomment-290363910
},
module: {
noParse: /polyfills-.*\.js/,
rules: [
{ test: /\.ts$/, loader: "ts-loader" },
{
// Mark files inside `@angular/core` as using SystemJS style dynamic imports.
// Removing this will cause deprecation warnings to appear.
test: /(\\|\/)@angular(\\|\/)core(\\|\/).+\.js$/,
parser: { system: true }
},
{
//load .node files
//ex: ./node_modules/sharp/build/Release/sharp.node
// https://github.com/lovell/sharp/issues/794#issuecomment-307188099
test: /\.node$/,
use: "node-loader"
}
]
},
plugins: [
new webpack.ContextReplacementPlugin(
// fixes WARNING Critical dependency: the request of a dependency is an expression
//https://webpack.js.org/plugins/context-replacement-plugin/
/(.+)?angular(\\|\/)core(.+)?/,
path.join(__dirname, "src"), // location of your src
{} // a map of your routes
),
new webpack.ContextReplacementPlugin(
// fixes WARNING Critical dependency: the request of a dependency is an expression
/(.+)?express(\\|\/)(.+)?/,
path.join(__dirname, "src"),
{}
)
]
};