forked from polylang/polylang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
60 lines (47 loc) · 1.76 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
/**
* @package Polylang
*/
/**
* External dependencies
*/
const path = require( 'path' );
const glob = require( 'glob' ).sync;
const { transformJsEntry, transformCssEntry } = require( '@wpsyntex/polylang-build-scripts' );
function configureWebpack( options ){
const mode = options.mode;
const isProduction = mode === 'production' || false;
console.log('Webpack mode:', mode);
console.log('isProduction:', isProduction);
console.log('dirname:', __dirname);
const commonFoldersToIgnore = [
'node_modules/**',
'vendor/**',
'tmp/**',
'webpack/**',
'**/build/**',
];
const jsFileNamesToIgnore = [
'js/lib/**',
'**/*.config.js',
'**/*.min.js',
];
const jsFileNames = glob( '**/*.js', { 'ignore': [ ...commonFoldersToIgnore, ...jsFileNamesToIgnore ] } ).map( filename => `./${ filename }`);
console.log( 'js files to minify:', jsFileNames );
const jsFileNamesEntries = [
...jsFileNames.map( transformJsEntry( path.resolve( __dirname ) + '/js/build', true ) ),
...jsFileNames.map( transformJsEntry( path.resolve( __dirname ) + '/js/build', false ) )
]
const cssFileNames = glob( '**/*.css', { 'ignore': [ ...commonFoldersToIgnore, '**/*.min.css' ] } ).map( filename => `./${ filename }`);
console.log( 'css files to minify:', cssFileNames );
// Prepare webpack configuration to minify css files to source folder as target folder and suffix file name with .min.js extension.
const cssFileNamesEntries = cssFileNames.map( transformCssEntry( path.resolve( __dirname ) + '/css/build', isProduction ) );
// Make webpack configuration.
const config = [
...jsFileNamesEntries, // Add config for js files.
...cssFileNamesEntries, // Add config for css files.
];
return config;
}
module.exports = ( env, options ) => {
return configureWebpack( options );
}