-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
executable file
·121 lines (118 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* webpack
*
* Triggered via NPM commands to build development or production
* environments with the commands:
*
* npm run dev
*
* or
*
* npm run build
*
* This file concatinates and minifies your CSS and JS and runs
* transformations where configured.
*/
const path = require( 'path' );
const webpack = require( 'webpack' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const convertToCamelCase = ( str ) => {
return str.replace(
/\W+(.)/g,
function( match, chr ) {
return chr.toUpperCase();
}
);
};
/**
* webpack main config
*/
module.exports = {
mode: 'production',
/**
* JavaScript entry points.
*
* Note that index.js in the blocks is the main entry point of the block,
* This is compiled into editor.js in the assets/js folder.
*/
entry: {
blocks: './src/blocks.js',
frontend: './src/frontend.js',
},
output: {
path: path.resolve( __dirname, './assets' ),
filename: 'js/[name].js',
},
devtool: 'cheap-eval-source-map',
module: {
rules: [
// Babel
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: [ '@babel/preset-react' ],
},
},
},
// Scss
{
test: /\.scss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: {
url: false,
sourceMap: false,
},
},
{
loader: 'postcss-loader',
options: {
plugins: [
require( 'autoprefixer' ),
],
},
},
{
loader: 'sass-loader',
options: {
url: false,
sourceMap: false,
},
},
],
},
],
},
externals: [
{
react: 'React',
'react-dom': 'ReactDOM',
jquery: 'jQuery',
lodash: 'lodash',
'highlight.js': 'hljs',
},
// Define Wordpress libraries as externals
// see https://webpack.js.org/configuration/externals/#function
function( context, request, callback ) {
const wpLibMatches = request.match( /^\@(wp|wordpress)\/(.*)/i );
if ( wpLibMatches ) {
return callback( null, 'window.wp.' + convertToCamelCase( wpLibMatches[ 2 ] ) );
}
callback();
},
],
plugins: [
new webpack.NamedModulesPlugin(),
new MiniCssExtractPlugin( {
filename: 'css/[name].css',
chunkFilename: 'css/[name].css',
} ),
],
};