forked from microfeed/microfeed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
159 lines (142 loc) · 3.62 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
const path = require('path');
const BundleTracker = require('webpack-bundle-tracker');
const ESLintPlugin = require('eslint-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const WebpackShellPluginNext = require('webpack-shell-plugin-next');
const prod = process.env.NODE_ENV === 'production';
const devPort = 9000;
const buildDir = 'build/';
const plugins = [];
let publicPath = `http://localhost:${devPort}/`;
if (prod) {
publicPath = `/${buildDir}`;
} else {
plugins.push(new WebpackShellPluginNext({
onBuildStart: {
// XXX: when edge-src/ has syntax error, webpack dev server will crash; after we restart, previous
// node processes may still be alive, which would take up the same PORT number and prevent dev server
// to run again. We have to kill all wrangler processes
scripts: ['ps aux | grep -e "node_modules/wrangler" | grep -e "proxy" | awk \'{print $2}\' | xargs kill -9'],
blocking: true,
parallel: false
},
}));
}
const entry = {
//
// CSS
//
admin_styles_css: './common/admin_styles.css',
//
// JS
//
// Admin
admin_home_js: './ClientAdminHomeApp/index.js',
edit_item_js: './ClientAdminItemsApp/EditItem/index.js',
all_items_js: './ClientAdminItemsApp/index.js',
edit_channel_js: './ClientAdminChannelApp/index.js',
settings_js: './ClientAdminSettingsApp/index.js',
custom_code_editor_js: './ClientAdminCustomCodeEditorApp/index.js',
};
module.exports = {
context: path.resolve(__dirname, './client-src'),
entry,
output: {
path: path.resolve(__dirname, `./public/${buildDir}`),
filename: '[name]-[fullhash].js',
publicPath,
},
plugins: [
...plugins,
new ESLintPlugin({
extensions: ['jsx', 'js'],
exclude: [
'node_modules',
],
emitWarning: true,
failOnError: false,
}),
new BundleTracker({filename: './functions/webpack-stats.json'}),
// Delete stale assets before each build
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [
'*.js',
'*.css',
'*.png',
'*.txt',
],
verbose: true,
dry: false,
}),
new MiniCssExtractPlugin({
filename: '[name]-[fullhash].css',
}),
],
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'swc-loader',
options: {
sync: true,
},
},
],
},
{
test: /\.less$/,
use: [{
loader: 'style-loader',
}, {
loader: 'css-loader',
}, {
loader: 'less-loader',
}],
},
{
test: /.*styles\.css$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: 'css-loader', options: { url: false } },
'postcss-loader',
],
},
{
test: /\.css$/,
exclude: /.*styles\.css$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader', options: { url: false } },
'postcss-loader',
],
},
{
test: /\.svg$/,
loader: 'svg-inline-loader'
},
],
},
devServer: {
static: [
{
directory: path.join(__dirname, './public/'),
},
{
directory: path.join(__dirname, './client-src/'),
},
],
headers: {
'Access-Control-Allow-Origin': '*',
},
compress: true,
port: devPort,
},
resolve: {
extensions: ['*', '.js', '.jsx'],
},
mode: prod ? 'production' : 'development',
};