-
Notifications
You must be signed in to change notification settings - Fork 156
/
webpack.config.js
116 lines (111 loc) · 2.95 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
const MiniCSSExtractPlugin = require( 'mini-css-extract-plugin' );
const { resolve } = require( 'path' );
/**
* Generate CSS file name.
*
* CSS only entry points are indicated with the suffix `-css` in the entry. This
* suffix is removed from the file name to avoid the tortologist `-css.css`.
*
* In some cases the CSS file name differs from the JavaScript filename. In a
* possibly foolhardy attempt to maintain backward compatibility, these values are
* hard coded here.
*
* @param {Object} pathData Entry point path data.
* @return {string} Resolved file name.
*/
const cssFileName = ( pathData ) => {
let name = pathData.chunk.name;
name = name.replace( /\-css$/, '' );
// Backward compatibility for divergent file names.
switch ( name ) {
case 'admin-pull':
name = 'admin-pull-table';
break;
}
return `css/${ name }.min.css`;
};
module.exports = {
...defaultConfig,
output: {
...defaultConfig.output,
filename: 'js/[name].min.js',
path: resolve( process.cwd(), 'dist' ),
},
entry: {
// ...defaultConfig.entry(),
'admin-external-connection': resolve(
process.cwd(),
'assets/js',
'admin-external-connection.js'
),
'admin-pull': resolve( process.cwd(), 'assets/js', 'admin-pull.js' ),
'admin-distributed-post': resolve(
process.cwd(),
'assets/js',
'admin-distributed-post.js'
),
push: resolve( process.cwd(), 'assets/js', 'push.js' ),
'gutenberg-syndicated-post': resolve(
process.cwd(),
'assets/js',
'gutenberg-syndicated-post.js'
),
'gutenberg-plugin': resolve(
process.cwd(),
'assets/js',
'gutenberg-plugin.js'
),
// CSS Only
'admin-css': resolve( process.cwd(), 'assets/css', 'admin.css' ),
'admin-site-health-css': resolve(
process.cwd(),
'assets/css',
'admin-site-health.css'
),
'admin-external-connections-css': resolve(
process.cwd(),
'assets/css',
'admin-external-connections.css'
), // Note the plural.
'admin-settings-css': resolve(
process.cwd(),
'assets/css',
'admin-settings.css'
),
'gutenberg-syndicated-post-css': resolve(
process.cwd(),
'assets/css',
'gutenberg-syndicated-post.scss'
),
'admin-syndicated-post-css': resolve(
process.cwd(),
'assets/css',
'admin-syndicated-post.scss'
),
'admin-edit-table-css': resolve(
process.cwd(),
'assets/css',
'admin-edit-table.css'
),
},
plugins: [
...defaultConfig.plugins.filter(
( plugin ) =>
plugin.constructor.name !==
'DependencyExtractionWebpackPlugin' &&
plugin.constructor.name !== 'MiniCssExtractPlugin'
),
new MiniCSSExtractPlugin( { filename: cssFileName } ),
new DependencyExtractionWebpackPlugin( {
injectPolyfill: true,
combineAssets: false,
requestToExternal( request ) {
if ( request === 'underscore' ) {
return '_';
}
},
} ),
],
};