forked from WPDevelopers/notificationx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.frontend.config.js
142 lines (138 loc) · 4.76 KB
/
webpack.frontend.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
141
142
const webpack = require('webpack');
const path = require("path");
const defaultConfig = require("@wordpress/scripts/config/webpack.config");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MiniCSSExtractPlugin = require("mini-css-extract-plugin");
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
const isProduction = process.env.NODE_ENV === "production";
const plugins = defaultConfig.plugins.filter(
(plugin) =>
plugin.constructor.name != "MiniCssExtractPlugin" &&
// plugin.constructor.name != "DependencyExtractionWebpackPlugin" &&
plugin.constructor.name != "CleanWebpackPlugin"
);
const config = {
...defaultConfig,
entry: {
frontend: path.resolve(
__dirname,
"nxdev/notificationx/frontend/index.tsx",
),
crossSite: path.resolve(
__dirname,
"nxdev/notificationx/frontend/crossSite.tsx"
),
"flashing-tab": path.resolve(
__dirname,
"nxdev/notificationx/frontend/flashing-tab.ts"
),
},
module: {
...defaultConfig.module,
rules: [
...defaultConfig.module.rules,
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
// {
// test: /\.(jpg|png|svg)$/,
// use: "url-loader",
// // type: "asset/source",
// dependency: { not: ['url'] },
// },
// {
// test: /\.(gif)$/,
// // use: "url-loader",
// type: 'asset/resource',
// },
],
},
resolve: {
...defaultConfig.resolve,
extensions: [".tsx", ".ts", ".js", ".jsx"],
},
output: {
...defaultConfig.output,
filename: "public/js/[name].js",
path: path.resolve(process.cwd(), isProduction ? "assets" : "nxbuild"),
chunkFilename: (pathData) => {
return `public/${pathData.chunk.name || pathData.chunk.id}.js`;
},
},
plugins: [
new CleanWebpackPlugin({
// dry: true,
cleanOnceBeforeBuildPatterns: [
"public/css/frontend.css",
"public/css/frontend.css.map",
"public/js/frontend.js",
"public/js/frontend.js.map",
"public/css/crossSite.css",
"public/css/crossSite.css.map",
"public/js/crossSite.js",
"public/js/crossSite.js.map",
],
}),
new MiniCSSExtractPlugin({
filename: ({ chunk }) => {
// if (!isProduction) {
// return `${chunk.name}.css`;
// }
return chunk.name == "admin"
? `admin/css/${chunk.name}.css`
: `public/css/${chunk.name}.css`;
},
}),
// new DependencyExtractionWebpackPlugin( {
// injectPolyfill: true,
// requestToExternal( request ) {
// if(request == '@wordpress/dom-ready') //
// return false;
// return undefined;
// },
// } ),
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
}),
...plugins,
],
optimization: {
...defaultConfig.optimization,
splitChunks: {
...defaultConfig.optimization.splitChunks,
// chunks(chunk) {
// // exclude `my-excluded-chunk`
// console.log(chunk.name);
// return chunk.name?.includes('locale/');
// },
cacheGroups: {
...defaultConfig.optimization.splitChunks.cacheGroups,
// vendors: false,
// moment: {
// test: /node_modules\/moment\/moment.js/,
// chunks: 'all',
// enforce: false,
// name: "js/moment",
// },
locale: {
test: /node_modules\/moment\/locale\/.*/,
chunks: 'all',
enforce: true,
name(module, chunks, cacheGroupKey) {
const moduleFileName = module
.identifier()
.split('/')
.reduceRight((item) => item);
// console.log(moduleFileName);
// console.log('name', module.identifier());
return 'locale/' + moduleFileName.replace('.js', '');
},
},
},
},
},
};
module.exports = config;