This repository was archived by the owner on Mar 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathwebpack.config.js
140 lines (135 loc) · 3.7 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
process.env.NODE_ENV = process.env.APPENV;
const config = require("config");
const _ = require("lodash");
const webpackMerge = require("webpack-merge");
const singleSpaDefaults = require("webpack-config-single-spa-react");
const autoprefixer = require("autoprefixer");
const path = require("path");
const webpack = require("webpack");
const unusedFilesWebpackPlugin = require("unused-files-webpack-plugin").default;
module.exports = (webpackConfigEnv) => {
const defaultConfig = singleSpaDefaults({
orgName: "topcoder",
projectName: "micro-frontends-earn-app",
webpackConfigEnv,
disableHtmlGeneration: true,
});
// const unusedFilesWebpackPlugin = defaultConfig.plugins.find(
// (p) => p.constructor.name === "UnusedFilesWebpackPlugin"
// );
// unusedFilesWebpackPlugin.globOptions.ignore.push(
// "assets/icons/*.svg",
// "__mocks__/**"
// );
new unusedFilesWebpackPlugin({
globOptions: {
ignore: [
"assets/icons/*.svg",
"__mocks__/**"
]
}
});
let cssLocalIdent;
if (process.env.APPMODE == "production") {
cssLocalIdent = "[hash:base64:6]";
} else {
cssLocalIdent = "earn_[path][name]___[local]___[hash:base64:6]";
}
// modify the webpack config however you'd like to by adding to this object
return webpackMerge.smart(defaultConfig, {
// we have to list here all the microapps which we would like to use in imports
// so webpack doesn't tries to import them
externals: {
"@topcoder/mfe-header": "@topcoder/mfe-header",
"react": "react",
"react-dom": "react-dom",
},
output: {
path: path.resolve(__dirname, "dist"),
publicPath: "earn-app",
},
module: {
rules: [
{
/* Loads jsx */
test: /\.(jsx?|svg)$/,
exclude: [
/node_modules/,
/[/\\]assets[/\\]fonts/,
/[/\\]assets[/\\]images/,
],
loader: "babel-loader",
},
{
/* Loads images */
test: /\.(svg|gif|jpe?g|png)$/,
exclude: [/[/\\]assets[/\\]fonts/],
loader: "file-loader",
options: {
outputPath: "images",
},
},
{
/* Loads fonts */
test: /\.(eot|otf|svg|ttf|woff2?)$/,
exclude: [/[/\\]assets[/\\]images/],
loader: "file-loader",
options: {
outputPath: "fonts",
},
},
{
/* Loads scss stylesheets. */
test: /\.scss$/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
modules: {
localIdentName: cssLocalIdent,
mode: "local",
},
},
},
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [autoprefixer],
},
},
},
"resolve-url-loader",
{
loader: "sass-loader",
options: {
sourceMap: true,
},
},
],
},
],
},
plugins: [
new webpack.DefinePlugin({
"process.env": {
..._.mapValues(config, (value) => JSON.stringify(value)),
APPENV: JSON.stringify(process.env.APPENV),
APPMODE: JSON.stringify(process.env.APPMODE),
},
}),
],
resolve: {
alias: {
styles: path.resolve(__dirname, "src/styles"),
assets: path.resolve(__dirname, "src/assets"),
},
},
devServer: {
hot: true,
host: "0.0.0.0",
port: 8008,
},
});
};