-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
57 lines (54 loc) · 1.59 KB
/
Copy pathwebpack.config.js
File metadata and controls
57 lines (54 loc) · 1.59 KB
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
/**
* External dependencies
*/
const path = require( 'path' );
const CopyPlugin = require( 'copy-webpack-plugin' );
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );
/**
* WordPress dependencies
*/
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const SRC_DIR = path.resolve( __dirname, 'assets/src' );
const BUILD_DIR = path.resolve( __dirname, 'assets/build' );
/**
* Single build for the theme.
*
* Reuses the `@wordpress/scripts` defaults (Babel, PostCSS, RTL generation,
* minification, `*.asset.php` dependency manifests) and only changes the
* entry points and output layout:
*
* - assets/src/js/*.js -> assets/build/js/*.js
* - assets/src/css/*.css -> assets/build/css/*.css (+ *-rtl.css); editor.css is
* loaded only in the block editor
* - assets/src/images/ -> assets/build/images/
*/
module.exports = {
...defaultConfig,
entry: {
'js/main': path.join( SRC_DIR, 'js/main.js' ),
'js/customizer': path.join( SRC_DIR, 'js/customizer.js' ),
'css/main': path.join( SRC_DIR, 'css/main.css' ),
'css/editor': path.join( SRC_DIR, 'css/editor.css' ),
},
output: {
...defaultConfig.output,
path: BUILD_DIR,
clean: true,
},
plugins: [
...defaultConfig.plugins,
// Drops the empty css/main.js that webpack emits for the CSS-only entry.
new RemoveEmptyScriptsPlugin( {
stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS,
} ),
new CopyPlugin( {
patterns: [
{
from: path.join( SRC_DIR, 'images' ),
to: path.join( BUILD_DIR, 'images' ),
noErrorOnMissing: true,
},
],
} ),
],
};