Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 16 additions & 26 deletions webpack.config.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const fs = require( 'fs' );
const { readFileSync } = require( 'node:fs' );
const path = require( 'node:path' );
const { execSync } = require( 'child_process' );
Expand All @@ -10,7 +9,7 @@ const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );

const SCHEMA_SRC = './schema/schema.json';
const SCHEMA_OUTPUT_NAME = 'schema.json';
const WP_PLUGIN_SCHEMA_PATH = path.join( 'src/plugin', SCHEMA_OUTPUT_NAME );
const SCHEMA_SRC_PATH = path.resolve( __dirname, SCHEMA_SRC );

module.exports = function ( env ) {
let targets = [ 'firefox', 'chrome' ];
Expand Down Expand Up @@ -71,6 +70,10 @@ function extensionModules( mode, target ) {
],
};

const watchOptions = {
ignored: [ SCHEMA_SRC_PATH ],
};

const webExtensionPolyfillPlugin = new webpack.ProvidePlugin( {
browser: 'webextension-polyfill',
} );
Expand Down Expand Up @@ -109,6 +112,7 @@ function extensionModules( mode, target ) {
webExtensionPolyfillPlugin,
envPlugin,
],
watchOptions,
},
// Extension content script.
{
Expand All @@ -122,6 +126,7 @@ function extensionModules( mode, target ) {
filename: path.join( 'content.js' ),
},
plugins: [ webExtensionPolyfillPlugin, envPlugin ],
watchOptions,
},
// The app.
{
Expand All @@ -142,10 +147,6 @@ function extensionModules( mode, target ) {
from: './src/ui/app.html',
to: path.join( targetPath, 'app.html' ),
},
],
} ),
new CopyPlugin( {
patterns: [
{
from: '**/*',
context: 'src/plugin/',
Expand All @@ -154,22 +155,20 @@ function extensionModules( mode, target ) {
},
to: path.join( targetPath, 'plugin' ),
},
{
from: SCHEMA_SRC,
to: path.join(
targetPath,
'plugin',
SCHEMA_OUTPUT_NAME
),
},
],
} ),
// Create plugin.zip.
new FileManagerPlugin( {
events: {
onEnd: {
copy: [
{
source: WP_PLUGIN_SCHEMA_PATH,
destination: path.join(
targetPath,
'plugin',
SCHEMA_OUTPUT_NAME
),
},
],
archive: [
{
source: path.join( targetPath, 'plugin' ),
Expand All @@ -187,6 +186,7 @@ function extensionModules( mode, target ) {
].concat(
mode === 'production' ? [ new MiniCssExtractPlugin() ] : []
),
watchOptions,
},
];
}
Expand All @@ -206,16 +206,6 @@ class EmitSubjectsSchemaPlugin {
execSync( './schema/build.mjs', { stdio: 'inherit' } );
const schema = readFileSync( SCHEMA_SRC );

// Write to WordPress plugin directory
await fs.promises.mkdir(
Comment thread
ashfame marked this conversation as resolved.
path.dirname( WP_PLUGIN_SCHEMA_PATH ),
{ recursive: true }
);
await fs.promises.writeFile(
WP_PLUGIN_SCHEMA_PATH,
schema
);

// Also emit for webpack output
compilation.emitAsset( SCHEMA_OUTPUT_NAME, {
source: () => schema,
Expand Down