forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared.js
More file actions
123 lines (114 loc) · 2.75 KB
/
shared.js
File metadata and controls
123 lines (114 loc) · 2.75 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
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
117
118
119
120
121
122
123
/**
* External dependencies
*/
const { DefinePlugin } = require( 'webpack' );
const TerserPlugin = require( 'terser-webpack-plugin' );
const postcss = require( 'postcss' );
const { join } = require( 'path' );
const baseDir = join( __dirname, '../../' );
const getBaseConfig = ( env ) => {
const mode = env.environment;
const config = {
target: 'browserslist',
mode,
optimization: {
moduleIds: mode === 'production' ? 'deterministic' : 'named',
minimizer: [
new TerserPlugin( {
extractComments: false,
} ),
],
},
module: {
rules: [
{
test: /\.js$/,
use: [ 'source-map-loader' ],
enforce: 'pre',
},
],
},
resolve: {
modules: [ baseDir, 'node_modules' ],
alias: {
'lodash-es': 'lodash',
},
},
stats: 'errors-only',
watch: env.watch,
plugins: [
new DefinePlugin( {
// Inject the `IS_GUTENBERG_PLUGIN` global, used for feature flagging.
'globalThis.IS_GUTENBERG_PLUGIN': JSON.stringify( false ),
// Inject the `IS_WORDPRESS_CORE` global, used for feature flagging.
'globalThis.IS_WORDPRESS_CORE': JSON.stringify( true ),
// Inject the `SCRIPT_DEBUG` global, used for dev versions of JavaScript.
'globalThis.SCRIPT_DEBUG': JSON.stringify(
mode === 'development'
),
} ),
],
};
if ( mode === 'development' && env.buildTarget === 'build/' ) {
config.mode = 'production';
config.optimization = {
minimize: false,
moduleIds: 'deterministic',
};
} else if ( mode !== 'production' ) {
config.devtool = process.env.SOURCEMAP || 'source-map';
}
return config;
};
const stylesTransform = ( mode ) => ( content ) => {
return postcss( [
require( 'cssnano' )( {
preset:
mode === 'production'
? 'default'
: [
'default',
{
discardComments: {
removeAll:
! content.includes( 'Copyright' ) &&
! content.includes( 'License' ),
},
normalizeWhitespace: false,
},
],
} ),
] )
.process( content, { from: 'src/app.css', to: 'dest/app.css' } )
.then( ( result ) => result.css );
};
const normalizeJoin = ( ...paths ) => join( ...paths ).replace( /\\/g, '/' );
const BUNDLED_PACKAGES = [
'@wordpress/dataviews',
'@wordpress/icons',
'@wordpress/interface',
'@wordpress/interactivity',
'@wordpress/sync',
'@wordpress/undo-manager',
'@wordpress/upload-media',
'@wordpress/fields',
];
const MODULES = [
'@wordpress/interactivity',
'@wordpress/interactivity-router',
];
const SCRIPT_AND_MODULE_DUAL_PACKAGES = [
'@wordpress/a11y',
'@wordpress/block-library',
];
const WORDPRESS_NAMESPACE = '@wordpress/';
module.exports = {
baseDir,
getBaseConfig,
normalizeJoin,
stylesTransform,
BUNDLED_PACKAGES,
MODULES,
SCRIPT_AND_MODULE_DUAL_PACKAGES,
WORDPRESS_NAMESPACE,
};