Fix admin extensions webpack config

This commit is contained in:
Chi-Hsuan Huang 2022-04-13 13:58:39 +08:00
parent 0ed8911875
commit ed8885f0b7
1 changed files with 14 additions and 11 deletions

View File

@ -10,13 +10,11 @@ const woocommerceAdminConfig = require( path.resolve(
) ); ) );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' ); const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const extArg = process.argv.find( ( arg ) => arg.startsWith( '--ext=' ) ); if ( ! process.env.WC_EXT ) {
if ( ! extArg ) {
throw new Error( 'Please provide an extension.' ); throw new Error( 'Please provide an extension.' );
} }
const extension = extArg.slice( 6 ); const extension = process.env.WC_EXT;
const extensionPath = path.join( __dirname, `${ extension }/js/index.js` ); const extensionPath = path.join( __dirname, `${ extension }/js/index.js` );
if ( ! fs.existsSync( extensionPath ) ) { if ( ! fs.existsSync( extensionPath ) ) {
@ -33,7 +31,7 @@ const webpackConfig = {
output: { output: {
filename: '[name]/dist/index.js', filename: '[name]/dist/index.js',
path: path.resolve( __dirname ), path: path.resolve( __dirname ),
libraryTarget: 'this', libraryTarget: 'window',
}, },
externals: woocommerceAdminConfig.externals, externals: woocommerceAdminConfig.externals,
module: { module: {
@ -89,12 +87,17 @@ const webpackConfig = {
}, },
}, },
plugins: [ plugins: [
new CopyWebpackPlugin( [ new CopyWebpackPlugin( {
{ patterns: [
from: path.join( __dirname, `${ extension }/` ), {
to: path.resolve( __dirname, `../../../../${ extension }/` ), from: path.join( __dirname, `${ extension }/` ),
}, to: path.resolve(
] ), __dirname,
`../../../../${ extension }/`
),
},
],
} ),
new MiniCssExtractPlugin( { new MiniCssExtractPlugin( {
filename: '[name]/dist/style.css', filename: '[name]/dist/style.css',
} ), } ),