forked from manfredsteyer/module-federation-with-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
105 lines (101 loc) · 2.92 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 AotPlugin = require("@ngtools/webpack").AngularCompilerPlugin;
const HtmlWebpackPlugin = require("html-webpack-plugin");
const path = require("path");
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const CopyPlugin = require('copy-webpack-plugin');
// const ContainerReferencePlugin = require("webpack/lib/container/ContainerReferencePlugin");
// const ContainerPlugin = require("webpack/lib/container/ContainerPlugin");
const shellConfig = {
entry: ["./projects/shell/src/polyfills.ts", "./projects/shell/src/main.ts"],
resolve: {
mainFields: ["browser", "module", "main"]
},
devServer: {
contentBase: path.join(__dirname, "dist/shell"),
port: 5000
},
module: {
rules: [
{ test: /\.ts$/, loader: "@ngtools/webpack" }
]
},
plugins: [
new ModuleFederationPlugin({
remotes: {
mfe1: "mfe1"
},
shared: ["@angular/core", "@angular/common", "@angular/router"]
}),
new AotPlugin({
skipCodeGeneration: false,
tsConfigPath: "./projects/shell/tsconfig.app.json",
directTemplateLoading: true,
entryModule: path.resolve(
__dirname,
"./projects/shell/src/app/app.module#AppModule"
)
}),
new CopyPlugin([
{ from: 'projects/shell/src/assets', to: 'assets' },
]),
new HtmlWebpackPlugin({
template: "./projects/shell/src/index.html"
})
],
output: {
filename: "[id].[name].js",
path: __dirname + "/dist/shell",
chunkFilename: "[id].[chunkhash].js"
},
mode: "production"
};
const mfe1Config = {
entry: ["./projects/mfe1/src/polyfills.ts", "./projects/mfe1/src/main.ts"],
resolve: {
mainFields: ["browser", "module", "main"]
},
devServer: {
contentBase: path.join(__dirname, "dist/mfe1"),
port: 3000
},
module: {
rules: [
{ test: /\.ts$/, loader: "@ngtools/webpack" }
]
},
plugins: [
new ModuleFederationPlugin({
name: "mfe1",
library: { type: "var", name: "mfe1" },
filename: "remoteEntry.js",
exposes: {
Component: './projects/mfe1/src/app/app.component.ts',
Module: './projects/mfe1/src/app/flights/flights.module.ts'
},
shared: ["@angular/core", "@angular/common", "@angular/router"]
}),
new AotPlugin({
skipCodeGeneration: false,
tsConfigPath: "./projects/mfe1/tsconfig.app.json",
directTemplateLoading: true,
entryModule: path.resolve(
__dirname,
"./projects/mfe1/src/app/app.module#AppModule"
)
}),
new CopyPlugin([
{ from: 'projects/mfe1/src/assets', to: 'assets' },
]),
new HtmlWebpackPlugin({
template: "./projects/mfe1/src/index.html"
})
],
output: {
publicPath: "http://localhost:3000/",
filename: "[name].js",
path: __dirname + "/dist/mfe1",
chunkFilename: "[id].[chunkhash].js"
},
mode: "production"
};
module.exports = [shellConfig, mfe1Config];