59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
const defaultConfig = require('@wordpress/scripts/config/webpack.config');
|
|
const WooCommerceDependencyExtractionWebpackPlugin = require('@woocommerce/dependency-extraction-webpack-plugin');
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
const path = require('path');
|
|
|
|
const wcDepMap = {
|
|
'@woocommerce/blocks-registry': ['wc', 'wcBlocksRegistry'],
|
|
'@woocommerce/settings' : ['wc', 'wcSettings']
|
|
};
|
|
|
|
const wcHandleMap = {
|
|
'@woocommerce/blocks-registry': 'wc-blocks-registry',
|
|
'@woocommerce/settings' : 'wc-settings'
|
|
};
|
|
|
|
const requestToExternal = (request) => {
|
|
if (wcDepMap[request]) {
|
|
return wcDepMap[request];
|
|
}
|
|
};
|
|
|
|
const requestToHandle = (request) => {
|
|
if (wcHandleMap[request]) {
|
|
return wcHandleMap[request];
|
|
}
|
|
};
|
|
|
|
// Export configuration.
|
|
module.exports = {
|
|
...defaultConfig,
|
|
entry: {
|
|
'frontend/blocks': '/resources/js/frontend/index.js'
|
|
},
|
|
output: {
|
|
path: path.resolve( __dirname, 'assets/js' ),
|
|
filename: '[name].js',
|
|
},
|
|
plugins: [
|
|
...defaultConfig.plugins.filter(
|
|
(plugin) =>
|
|
plugin.constructor.name !== 'DependencyExtractionWebpackPlugin'
|
|
),
|
|
new WooCommerceDependencyExtractionWebpackPlugin({
|
|
requestToExternal,
|
|
requestToHandle
|
|
}),
|
|
new CopyWebpackPlugin({
|
|
patterns: [
|
|
{ from: 'resources/js/frontend/modalCheckout.js', to: 'frontend/', info: { minimized: true } },
|
|
{ from: 'resources/js/frontend/blocksModalCheckout.js', to: 'frontend/', info: { minimized: false } },
|
|
{ from: 'resources/js/backend/gatewayIconMedia.js', to: 'backend/', info: { minimized: true } },
|
|
{ from: 'resources/js/backend/apiKeyRedirect.js', to: 'backend/', info: { minimized: true } },
|
|
{ from: 'resources/js/backend/notifications.js', to: 'backend/', info: { minimized: true } },
|
|
{ from: 'resources/js/backend/orderStatesWarning.js', to: 'backend/', info: { minimized: true } }
|
|
]
|
|
})
|
|
]
|
|
};
|