Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
123 lines (115 loc) · 2.38 KB
/
Copy pathwebpack.config.js
File metadata and controls
123 lines (115 loc) · 2.38 KB
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
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const IgnoreEmitPlugin = require("ignore-emit-webpack-plugin");
const isProduction = process.env.NODE_ENV === 'production';
var config = {
watch: !isProduction,
mode: isProduction ? "production" : "development",
};
const projectFiles = {
// SCSS & JScript Compile lists
scss: [
{
filename: "admin",
entry: ["./assets/src/scss/admin.scss"],
path: "assets/css",
},
{
filename: "frontend",
entry: ["./assets/src/scss/frontend.scss"],
path: "assets/css",
},
],
js: [
{
filename: "admin",
entry: ["./assets/src/js/admin.js"],
path: "assets/js",
},
{
filename: "frontend",
entry: ["./assets/src/js/frontend.js"],
path: "assets/js",
},
],
};
let scssConfig = projectFiles.scss.map((item) =>
Object.assign({}, config, {
entry: {
[item.filename]: item.entry,
},
output: {
path: path.resolve(__dirname, item.path),
},
module: {
rules: [
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"sass-loader",
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css",
}),
new IgnoreEmitPlugin(/\.js$/), // in case of css, a new admn.js file is craeted, that's why we are ignoring here
],
})
);
let jsConfig = projectFiles.js.map((item) =>
Object.assign({}, config, {
entry: {
[item.filename]: item.entry,
},
output: {
path: path.resolve(__dirname, item.path),
chunkFilename: "chunk/[name].chunk.js",
},
module: {
rules: [
{
test: /\.m?(js|jsx)$/,
exclude: /(node_modules)/,
loader: "babel-loader",
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
{
test: /\.(png|jpe?g|gif)$/i,
loader: "file-loader",
options: {
name: "[path][name].[ext]",
},
},
],
},
performance: { hints: false },
optimization: {
minimize: isProduction,
},
resolve: {
fallback: { fs: false },
fallback: {
"react/jsx-runtime": "react/jsx-runtime.js",
"react/jsx-dev-runtime": "react/jsx-dev-runtime.js",
},
},
externals: {
react: "React",
"react-dom": "ReactDOM",
antd: "antd",
lodash: "_",
},
})
);
let configModule = [...scssConfig, ...jsConfig];
// Return Array of Configurations
module.exports = configModule;