Fix admin extensions webpack config
This commit is contained in:
parent
0ed8911875
commit
ed8885f0b7
|
@ -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',
|
||||||
} ),
|
} ),
|
||||||
|
|
Loading…
Reference in New Issue