-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
webpack.config.js
executable file
·102 lines (97 loc) · 2.31 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
const defaults = require('@wordpress/scripts/config/webpack.config');
const ESLintPlugin = require('eslint-webpack-plugin');
const StylelintPlugin = require('stylelint-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
module.exports = {
entry: {
'frontend/ajax-load-more': './src/frontend/js/ajax-load-more.js',
'frontend/ajax-load-more.min': './src/frontend/js/ajax-load-more.js',
'admin/index': './src/admin/js/index.js',
'blocks/core/index': './src/blocks/core/index.js',
'blocks/filters/index': './src/blocks/filters/index.js',
},
output: {
path: path.join(__dirname, 'build'),
assetModuleFilename: (pathData) => {
const filepath = path.dirname(pathData.filename).split('/').slice(1).join('/');
return `${filepath}/[name][ext]`;
},
library: 'ajaxloadmore',
libraryTarget: 'var',
},
module: {
rules: [
{
test: /\.(webp|png|jpe?g|gif)$/,
type: 'asset/resource',
},
{
test: /\.js?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-react', { targets: 'defaults' }]],
},
},
},
{
test: /\.(scss|css)$/,
exclude: '/node_modules',
use: [
'style-loader',
{
loader: MiniCssExtractPlugin.loader,
options: {
esModule: false,
},
},
'css-loader',
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
],
},
],
},
plugins: [
...defaults.plugins,
/**
* Minify CSS files.
*
* @see https://www.npmjs.com/package/mini-css-extract-plugin
*/
new MiniCssExtractPlugin(),
/**
* Copy the following files to build directory.
*
* @see https://www.npmjs.com/package/copy-webpack-plugin
*/
new CopyPlugin({
patterns: [
{
from: 'src/frontend/img/placeholder.png',
to: 'frontend/img/placeholder.png',
noErrorOnMissing: true,
},
],
}),
/**
* Report JS warnings and errors to the command line.
*
* @see https://www.npmjs.com/package/eslint-webpack-plugin
*/
new ESLintPlugin(),
/**
* Report css warnings and errors to the command line.
*
* @see https://www.npmjs.com/package/stylelint-webpack-plugin
*/
new StylelintPlugin(),
],
};