| 1 | /** |
| 2 | * External dependencies |
| 3 | */ |
| 4 | const { join } = require( 'path' ); |
| 5 | |
| 6 | const DEFAULT_ENV = { |
| 7 | environment: 'production', |
| 8 | watch: false, |
| 9 | buildTarget: false, |
| 10 | }; |
| 11 | |
| 12 | module.exports = function( env = DEFAULT_ENV ) { |
| 13 | const mode = env.environment; |
| 14 | const suffix = mode === 'production' ? '.min' : ''; |
| 15 | const buildTarget = env.buildTarget || ( mode === 'production' ? 'build' : 'src' ); |
| 16 | |
| 17 | return { |
| 18 | mode, |
| 19 | |
| 20 | entry: { |
| 21 | lodash: 'lodash', |
| 22 | 'wp-polyfill': '@babel/polyfill', |
| 23 | 'wp-polyfill-fetch': 'whatwg-fetch', |
| 24 | 'wp-polyfill-element-closest': 'element-closest', |
| 25 | 'wp-polyfill-node-contains': 'polyfill-library/polyfills/Node/prototype/contains/polyfill.js', |
| 26 | 'wp-polyfill-url': 'core-js/modules/web.url.js', // 'whatwg-url', |
| 27 | 'wp-polyfill-dom-rect': 'polyfill-library/polyfills/DOMRect/polyfill.js', |
| 28 | 'wp-polyfill-formdata': 'formdata-polyfill', |
| 29 | 'moment': 'moment', |
| 30 | 'react': 'react', |
| 31 | 'react-dom': 'react-dom', |
| 32 | }, |
| 33 | |
| 34 | output: { |
| 35 | filename: `[name]${ suffix }.js`, |
| 36 | path: join( __dirname, `../../${ buildTarget }/wp-includes/js/dist` ), |
| 37 | }, |
| 38 | |
| 39 | stats: { |
| 40 | children: false, |
| 41 | }, |
| 42 | |
| 43 | watch: env.watch, |
| 44 | }; |
| 45 | }; |