-
Notifications
You must be signed in to change notification settings - Fork 23
/
webpack.config.js
133 lines (125 loc) · 2.96 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
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const UnminifiedWebpackPlugin = require('unminified-webpack-plugin')
const defaultConfig = require('@wordpress/scripts/config/webpack.config')
const isProduction = process.env.NODE_ENV === 'production'
const rules = {
rules: [
// js babelization
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
// sass compilation
{
test: /\.(sass|scss)$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader', 'postcss-loader']
},
// loader for images and icons (only required if css references image files)
{
test: /\.(png|jpg|gif)$/,
type: 'asset/resource',
generator: {
filename: './assets/images/[name][ext]',
}
},
]
}
const plugins = (filePath) => {
return [
new UnminifiedWebpackPlugin(),
// css extraction into dedicated file
new MiniCssExtractPlugin({
filename: filePath
}),
]
}
//Public configs
const publicConfig = {
entry: {
'join-via-browser': './src/public/js/join-via-browser.js',
public: './src/public/js/public.js',
shortcode: './src/public/js/shortcode.js'
},
output: {
filename: './assets/public/js/[name].min.js',
path: path.resolve(__dirname)
},
module: rules,
plugins: plugins('./assets/public/css/style.min.css'),
}
//Admin Configs
const backendConfig = {
entry: {
'script': './src/admin/js/script.js',
},
output: {
filename: './assets/admin/js/[name].min.js',
path: path.resolve(__dirname)
},
module: rules,
plugins: plugins('./assets/admin/css/style.min.css'),
}
//Default WP configs
const wp = {
...defaultConfig,
entry: {
...defaultConfig.entry,
index: path.resolve(process.cwd(), 'src/block', 'index.js'),
}
}
let modules = [wp, publicConfig, backendConfig]
if (isProduction) {
let webSDKConfig = {
cache: false,
entry: {
'zoom-meeting': {
import: './src/public/vendor/zoom-meeting.js',
dependOn: 'websdk',
},
'websdk': '@zoom/meetingsdk'
},
output: {
filename: './assets/vendor/zoom/websdk/[name].bundle.js',
path: path.resolve(__dirname)
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
},
{
test: /\.(jpg|png|svg)$/,
type: 'asset'
}
]
},
resolve: {
extensions: ['.js', '.jsx']
},
externals: {
'babel-polyfill': 'babel-polyfill',
react: 'React',
'react-dom': 'ReactDOM',
redux: 'Redux',
'redux-thunk': 'ReduxThunk',
lodash: {
commonjs: 'lodash',
amd: 'lodash',
root: '_',
var: '_'
}
},
target: 'web',
mode: 'production'
}
modules.push(webSDKConfig)
}
module.exports = modules