-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwebpack.config.js
More file actions
89 lines (77 loc) · 2.02 KB
/
webpack.config.js
File metadata and controls
89 lines (77 loc) · 2.02 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const IgnoreEmitPlugin = require( 'ignore-emit-webpack-plugin' );
const path = require( 'path' );
const CssoWebpackPlugin = require( 'csso-webpack-plugin' ).default;
const FixStyleOnlyEntriesPlugin = require( 'webpack-fix-style-only-entries' );
const camelCaseDash = ( string ) =>
string.replace( /-([a-z])/g, ( _match, letter ) => letter.toUpperCase() );
const externals = [
'api-fetch',
'block-editor',
'blocks',
'components',
'compose',
'data',
'date',
'htmlEntities',
'hooks',
'edit-post',
'element',
'editor',
'i18n',
'plugins',
'viewport',
'ajax',
'codeEditor',
'rich-text',
'primitives',
];
const globals = externals.reduce(
( external, name ) => ( {
...external,
[ `@wordpress/${ name }` ]: `wp.${ camelCaseDash( name ) }`,
} ),
{}
);
const config = {
...defaultConfig,
entry: {
gutenberg: './packages/gutenberg/src/index.js',
'gutenberg-styling': './packages/gutenberg/src/style.scss',
'blocks-library': './packages/blocks-library/src/index.js',
'blocks-library-editor-style':
'./packages/blocks-library/src/editor.scss',
'blocks-library-frontend-style':
'./packages/blocks-library/src/style.scss',
'cf7-blocks-integrate': './packages/cf7-integrate/src/index.js',
'cf7-blocks-integrate-style': './packages/cf7-integrate/src/style.scss',
},
output: {
clean: false,
path: path.join( __dirname, './dist' ),
},
plugins: [
...defaultConfig.plugins,
new MiniCssExtractPlugin( {
filename: ( pathData ) => {
const filename = pathData.chunk.name.replace(
/(style-|-style)/g,
''
);
return `${ filename }.css`;
},
} ),
// new FixStyleOnlyEntriesPlugin(),
// TODO: can we implement a better logic, other than surpressing the build chunks?
new IgnoreEmitPlugin( /(-style)/i ),
],
externals: {
wp: 'wp',
lodash: 'lodash',
react: 'React',
'react-dom': 'ReactDOM',
...globals,
},
};
module.exports = config;