-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
97 lines (91 loc) · 2.63 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
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const StandaloneSingleSpaPlugin = require("standalone-single-spa-webpack-plugin");
const packageJson = require("./package.json");
const isAnyOf = (value, list) => list.includes(value);
module.exports = (env, argv) => {
let prodMode = argv.p || argv.mode === "production";
return {
mode: prodMode ? "production" : "development",
output: {
filename: `index.js`,
libraryTarget: "system",
path: path.resolve(process.cwd(), "dist"),
uniqueName: packageJson.name,
publicPath: "",
},
module: {
rules: [
{
parser: {
system: false,
},
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
},
{
test: /\.html$/i,
use: ["html-loader"],
},
{
test: /\.css$/i,
use: [
"style-loader",
{
loader: "css-loader",
options: {
importLoaders: 1,
modules: true,
},
},
{
loader: "postcss-loader",
},
],
},
],
},
plugins: [
// These plugins enable standalone mode for local development
!prodMode && new HtmlWebpackPlugin(),
new StandaloneSingleSpaPlugin({
appOrParcelName: packageJson.name,
disabled: prodMode,
}),
].filter(Boolean),
devtool: "source-map",
devServer: {
compress: true,
historyApiFallback: true,
headers: {
"Access-Control-Allow-Origin": "*",
},
onListening: function ({
server /* https://nodejs.org/api/net.html#class-netserver */,
compiler,
}) {
if (!server)
throw new Error("webpack-dev-server is missing a server instance");
// config values
const { port: serverPort, address } = server.address();
const { publicPath, filename } = compiler.options.output;
// derived values
const protocol = compiler.options.devServer.https
? "https://"
: "http://";
const host = address === "::" ? "localhost" : address;
const port = Boolean(serverPort) ? `:${serverPort}` : "";
const path = isAnyOf(publicPath, ["", "auto"]) ? "/" : publicPath;
console.log(
`\n ⚡️ single-spa vanilla JS app entry: ${protocol}${host}${port}${path}${filename}\n`
);
},
},
externals: ["single-spa", "@actionanand/utility"],
};
};