-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathwebpack.config.js
139 lines (132 loc) · 5.95 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
const path = require('node:path');
const TerserPlugin = require('terser-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const webpack = require('webpack');
module.exports = (env, options) => {
const mode = options.mode || 'development';
const config = {
mode,
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(js|ts|tsx)$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.(png|jp(e*)g|gif|webp)$/,
use: [
{
loader: 'file-loader',
options: {
name: 'images/[hash]-[name].[ext]',
},
},
],
},
{
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
use: ['@svgr/webpack'],
},
],
},
plugins: [new webpack.ProvidePlugin({ React: 'react' })],
externals: {
react: 'React',
'react-dom': 'ReactDOM',
'@wordpress/i18n': 'wp.i18n',
},
devtool: 'source-map',
};
if ('production' === mode) {
config.devtool = false;
config.optimization = {
splitChunks: {
cacheGroups: {
shared: {
test: /[\\/]assets[\\/]react[\\/]v3[\\/]shared[\\/]/,
name: 'tutor-shared.min',
chunks: 'all',
},
},
},
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
compress: false,
ecma: 6,
mangle: true,
},
extractComments: false,
}),
],
};
}
const react_blueprints = [
{
dest_path: './assets/js',
src_files: {
'tutor.min': './assets/react/v2/common.js',
'tutor-front.min': './assets/react/front/tutor-front.js',
'tutor-admin.min': './assets/react/admin-dashboard/tutor-admin.js',
'tutor-setup.min': './assets/react/admin-dashboard/tutor-setup.js',
'tutor-gutenberg.min': './assets/react/gutenberg/index.js',
'tutor-course-builder.min': './assets/react/v3/entries/course-builder/index.tsx',
'tutor-order-details.min': './assets/react/v3/entries/order-details/index.tsx',
'tutor-coupon.min': './assets/react/v3/entries/coupon-details/index.tsx',
'tutor-tax-settings.min': './assets/react/v3/entries/tax-settings/index.tsx',
'tutor-payment-settings.min': './assets/react/v3/entries/payment-settings/index.tsx',
'tutor-addon-list.min': './assets/react/v3/entries/addon-list/index.tsx',
}
}
];
const configEditors = [];
for (let i = 0; i < react_blueprints.length; i++) {
const { src_files, dest_path } = react_blueprints[i];
configEditors.push(
Object.assign({}, config, {
name: 'configEditor',
entry: src_files,
output: {
path: path.resolve(dest_path),
filename: '[name].js',
chunkFilename: 'lazy-chunks/[name].[contenthash].min.js',
clean: true,
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
fallback: {
fs: false,
path: false,
os: false,
},
alias: {
'@TutorShared': path.resolve(__dirname, './assets/react/v3/shared'),
'@SharedImages': path.resolve(__dirname, './assets/react/v3/public/images'),
'@CourseBuilderComponents': path.resolve(__dirname, './assets/react/v3/entries/course-builder/components/'),
'@CourseBuilderServices': path.resolve(__dirname, './assets/react/v3/entries/course-builder/services/'),
'@CourseBuilderConfig': path.resolve(__dirname, './assets/react/v3/entries/course-builder/config/'),
'@CourseBuilderPages': path.resolve(__dirname, './assets/react/v3/entries/course-builder/pages/'),
'@CourseBuilderUtils': path.resolve(__dirname, './assets/react/v3/entries/course-builder/utils/'),
'@CourseBuilderContexts': path.resolve(__dirname, './assets/react/v3/entries/course-builder/contexts/'),
'@OrderComponents': path.resolve(__dirname, './assets/react/v3/entries/order-details/components/'),
'@OrderServices': path.resolve(__dirname, './assets/react/v3/entries/order-details/services/'),
'@OrderAtoms': path.resolve(__dirname, './assets/react/v3/entries/order-details/atoms/'),
'@OrderContexts': path.resolve(__dirname, './assets/react/v3/entries/order-details/contexts/'),
'@CouponComponents': path.resolve(__dirname, './assets/react/v3/entries/coupon-details/components/'),
'@CouponServices': path.resolve(__dirname, './assets/react/v3/entries/coupon-details/services/'),
'@AddonList': path.resolve(__dirname, './assets/react/v3/entries/addon-list/'),
},
},
}),
);
}
return [...configEditors];
};