| 1 |
const path = require( 'path' ); |
| 2 |
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' ); |
| 3 |
|
| 4 |
const buildDir = path.resolve( __dirname, 'build' ); |
| 5 |
|
| 6 |
/** |
| 7 |
* Main bundle (index.js) — standard wp-scripts config with WP dependency |
| 8 |
* extraction. Runs in the parent page context. |
| 9 |
*/ |
| 10 |
const mainConfig = { |
| 11 |
...defaultConfig, |
| 12 |
entry: { |
| 13 |
index: path.resolve( __dirname, 'src/index.js' ), |
| 14 |
}, |
| 15 |
output: { |
| 16 |
...defaultConfig.output, |
| 17 |
path: buildDir, |
| 18 |
}, |
| 19 |
}; |
| 20 |
|
| 21 |
/** |
| 22 |
* Iframe bundle (iframe.js) — standalone IIFE that runs inside a sandboxed |
| 23 |
* iframe. WordPress dependency extraction is disabled so that d3 and |
| 24 |
* topojson are bundled inline (the iframe has no access to wp.* globals). |
| 25 |
*/ |
| 26 |
const iframeConfig = { |
| 27 |
...defaultConfig, |
| 28 |
entry: { |
| 29 |
iframe: path.resolve( __dirname, 'src/iframe.js' ), |
| 30 |
}, |
| 31 |
output: { |
| 32 |
...defaultConfig.output, |
| 33 |
path: buildDir, |
| 34 |
}, |
| 35 |
// Remove DependencyExtractionWebpackPlugin — iframe has no WP globals. |
| 36 |
plugins: defaultConfig.plugins.filter( |
| 37 |
( plugin ) => plugin.constructor.name !== 'DependencyExtractionWebpackPlugin' |
| 38 |
), |
| 39 |
// Bundle d3/topojson inline; do not treat anything as external. |
| 40 |
externals: {}, |
| 41 |
}; |
| 42 |
|
| 43 |
module.exports = [ mainConfig, iframeConfig ]; |
| 44 |
|