-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
47 lines (42 loc) · 1.39 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
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const LiveReloadPlugin = require( 'webpack-livereload-plugin' );
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
const { CleanWebpackPlugin } = require( 'clean-webpack-plugin' );
const path = require( 'path' );
const glob = require('glob');
const isProduction = process.env.NODE_ENV === 'development';
const getLiveReloadPort = ( inputPort ) => {
const parsedPort = parseInt( inputPort, 10 );
return Number.isInteger( parsedPort ) ? parsedPort : 35729;
};
function getEntries() {
const out = {};
glob.sync("./src/block-library/**/index.js").forEach(entry => {
out[entry.split('/')[3]] = entry;
});
return out;
};
module.exports = {
...defaultConfig,
entry: getEntries,
output: {
filename: 'js/[name]/[name].js',
path: path.resolve(process.cwd(), 'build')
},
plugins: [
new CleanWebpackPlugin({
cleanAfterEveryBuildPatterns: ['!fonts/**', '!images/**'],
}),
new MiniCssExtractPlugin({
filename: 'css/[name].css'
}),
process.env.WP_BUNDLE_ANALYZER && new BundleAnalyzerPlugin(),
!isProduction &&
new LiveReloadPlugin({
port: getLiveReloadPort(process.env.WP_LIVE_RELOAD_PORT),
}),
!process.env.WP_NO_EXTERNALS &&
new DependencyExtractionWebpackPlugin(),
].filter(Boolean)
}