-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
73 lines (68 loc) · 1.91 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
const WordPressConfig = require( '@wordpress/scripts/config/webpack.config' );
const path = require( 'path' );
const glob = require( 'glob' );
/**
* Help make webpack entries to the correct format with name: path
* Modify name to exclude path and file extension
*
* @param {Object} paths
*/
const entryObject = ( paths ) => {
const entries = {};
paths.forEach( function ( filePath ) {
let fileName = filePath.split( '/' ).slice( -1 )[ 0 ];
fileName = fileName.replace( /\.[^/.]+$/, '' );
if ( ! fileName.startsWith( '_' ) ) {
entries[ fileName ] = filePath;
}
} );
return entries;
};
/**
* Extend the default WordPress/Scripts webpack to make entries and output more dynamic.
* This checks the assts/js and assets/scss folder for any .js* and .scss files and compiles those to separate files
*
* Latest @Wordpress/Scripts webpack config: https://github.com/WordPress/gutenberg/blob/master/packages/scripts/config/webpack.config.js
*/
module.exports = {
...WordPressConfig,
entry: entryObject( glob.sync( './assets/{scss,js}/*.{scss,js*}' ) ),
output: {
filename: '[name].js',
path: path.resolve( process.cwd(), 'build' ),
publicPath: '/content/plugins/ledyer-checkout-for-woocommerce/build/',
},
module: {
...WordPressConfig.module,
rules: [
...WordPressConfig.module.rules,
{
test: /\.(png|jp(e*)g|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: 'images/[name].[ext]',
},
},
],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
{
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]', // TODO: if multiple folders inside the fonts folder with the same filename inside the folders. this will override files with the latest compiled file
},
},
],
},
],
},
plugins: [
...WordPressConfig.plugins.filter(
( plugin ) => plugin.constructor.name !== 'CleanWebpackPlugin'
),
],
};