-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
170 lines (163 loc) · 3.81 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
160
161
162
163
164
165
166
167
168
169
170
const path = require('path');
// Plugins
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssoWebpackPlugin = require('csso-webpack-plugin').default;
const TerserJSPlugin = require('terser-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
const jsExternals = {
jquery: 'jQuery',
'@yaireo/tagify': 'Tagify',
select2: 'select2',
// WordPress Packages.
'@wordpress/hooks': 'wp.hooks',
}
const jsEntryPoints = {
// Frontend
ajax_tooltip: './source/js/ajax-tooltips.js',
search: './source/js/wppedia-search.js',
// Backend
edit: './source/js/admin/edit/edit.js',
options: './source/js/admin/options/options.js',
};
const isDev = process.argv[process.argv.indexOf('--mode') + 1] === 'development';
const cssEntryPoints = {
// Frontend
style: './source/scss/_main.scss',
// Frontend for inline usage
'tooltip-theme-light-border': './source/scss/components/tooltip/tippy-theme-light-border.scss',
'tooltip-theme-material': './source/scss/components/tooltip/tippy-theme-material.scss',
'tooltip-theme-translucent': './source/scss/components/tooltip/tippy-theme-translucent.scss',
// Backend
admin: './source/scss/admin/_main.scss'
};
module.exports = [
// Compile Javascript
{
mode: isDev ? 'development' : 'production',
entry: jsEntryPoints,
optimization: {
minimize: !isDev,
minimizer: [
new TerserJSPlugin({
terserOptions: {
output: {
comments: false,
},
},
extractComments: false,
})
],
},
output: {
path: path.resolve(__dirname, 'dist/js'),
filename: '[name].bundle.js'
},
externals: jsExternals,
module: {
rules: [
{
test: /\.(jsx?)$/,
exclude: /node_modules/,
use: ['babel-loader']
},
]
},
plugins: [
new DependencyExtractionWebpackPlugin(),
]
},
// Compile CSS
{
mode: isDev ? 'development' : 'production',
entry: cssEntryPoints,
output: {
path: path.resolve(__dirname, 'dist/css'),
filename: '[name].bundle.js',
assetModuleFilename: '../asset/[name][ext]',
},
optimization: {
minimize: !isDev,
minimizer: [
new TerserJSPlugin({
terserOptions: {
output: {
comments: false,
},
},
extractComments: false,
}),
new CssMinimizerPlugin({})
],
},
module: {
rules: [
{
test: /\.(png|jpg|jpeg|gif|ico)$/,
type: 'asset/resource'
},
{
test: /\.svgz?$/,
type: 'asset/resource',
use: [
{
loader: 'svgo-loader'
}
]
},
{
test: /\.(pc|sa|sc|c)ss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
esModule: false
}
},
'css-loader',
'postcss-loader',
'resolve-url-loader',
'sass-loader',
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].min.css',
chunkFilename: '[id].css'
}),
new CssoWebpackPlugin()
],
},
{
mode: isDev ? 'development' : 'production',
entry: {},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].bundle.js'
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: 'tagify.(min.js|css)',
to: path.resolve(__dirname, 'dist/vendor/tagify'),
context: path.resolve(__dirname, 'node_modules/@yaireo/tagify/dist')
},
{
from: 'select2.min.css',
to: path.resolve(__dirname, 'dist/vendor/select2'),
context: path.resolve(__dirname, 'node_modules/select2/dist/css')
},
{
from: 'select2.min.js',
to: path.resolve(__dirname, 'dist/vendor/select2'),
context: path.resolve(__dirname, 'node_modules/select2/dist/js')
},
]
})
]
}
];