-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs-files.js
43 lines (38 loc) · 1.1 KB
/
js-files.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
/**
* @package Polylang
*/
/**
* External dependencies
*/
const path = require( 'path' );
/**
* Peer dependencies
* These need to be installed in the consuming package.
*/
const TerserPlugin = require( 'terser-webpack-plugin' );
/**
* Prepare webpack configuration to minify js files to source folder as target folder and suffix file name with .min.js extension.
* @param {string[]} jsFileNames Source files to build.
* @param {boolean} minimize True to generate minified files.
*/
function transformJsEntry( destination, minimize = false ) {
return ( filename ) => {
const entry = {};
entry[ path.parse( filename ).name ] = filename;
const output = {
filename: `${path.parse( filename ).name}${minimize ? '.min' : '' }.js`,
path: destination,
iife: false, // Avoid Webpack to wrap files into a IIFE which is not needed for this kind of javascript files.
};
const config = {
entry: entry,
output: output,
optimization: {
minimize: minimize,
minimizer: [ new TerserPlugin( { extractComments: false } ) ]
}
};
return config;
}
}
module.exports = { transformJsEntry };