From 5c97f319da22e5d95dbef933f00a65396049f074 Mon Sep 17 00:00:00 2001 From: ashfame Date: Wed, 11 Dec 2024 15:49:45 +0400 Subject: [PATCH 1/6] do not drop a schema.json in WP plugin src dir (src/plugins) --- webpack.config.cjs | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/webpack.config.cjs b/webpack.config.cjs index f512ae4c..341f6593 100644 --- a/webpack.config.cjs +++ b/webpack.config.cjs @@ -10,7 +10,6 @@ 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 ); module.exports = function ( env ) { let targets = [ 'firefox', 'chrome' ]; @@ -160,16 +159,6 @@ function extensionModules( mode, target ) { new FileManagerPlugin( { events: { onEnd: { - copy: [ - { - source: WP_PLUGIN_SCHEMA_PATH, - destination: path.join( - targetPath, - 'plugin', - SCHEMA_OUTPUT_NAME - ), - }, - ], archive: [ { source: path.join( targetPath, 'plugin' ), @@ -206,16 +195,6 @@ class EmitSubjectsSchemaPlugin { execSync( './schema/build.mjs', { stdio: 'inherit' } ); const schema = readFileSync( SCHEMA_SRC ); - // Write to WordPress plugin directory - await fs.promises.mkdir( - 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, From 4343b3b9fd14b296f725fda7e96e2a76c928f9d3 Mon Sep 17 00:00:00 2001 From: ashfame Date: Wed, 11 Dec 2024 15:50:14 +0400 Subject: [PATCH 2/6] merge 2 CopyPlugin instances --- webpack.config.cjs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/webpack.config.cjs b/webpack.config.cjs index 341f6593..35fd9b33 100644 --- a/webpack.config.cjs +++ b/webpack.config.cjs @@ -141,10 +141,6 @@ function extensionModules( mode, target ) { from: './src/ui/app.html', to: path.join( targetPath, 'app.html' ), }, - ], - } ), - new CopyPlugin( { - patterns: [ { from: '**/*', context: 'src/plugin/', From dfd3f97fb5e700ea46106d3f9e80c80b68d40f76 Mon Sep 17 00:00:00 2001 From: ashfame Date: Wed, 11 Dec 2024 16:18:44 +0400 Subject: [PATCH 3/6] copy generated schema.json to plugins dir in build dir --- webpack.config.cjs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/webpack.config.cjs b/webpack.config.cjs index 35fd9b33..a3733a86 100644 --- a/webpack.config.cjs +++ b/webpack.config.cjs @@ -149,6 +149,14 @@ function extensionModules( mode, target ) { }, to: path.join( targetPath, 'plugin' ), }, + { + from: './schema/schema.json', + to: path.join( + targetPath, + 'plugin', + 'schema.json' + ), + }, ], } ), // Create plugin.zip. From 91978f2601efee07b9d54b607226e5ff04c32e1a Mon Sep 17 00:00:00 2001 From: ashfame Date: Wed, 11 Dec 2024 19:02:43 +0400 Subject: [PATCH 4/6] configure watch options for webpack to ignore schema src file --- webpack.config.cjs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/webpack.config.cjs b/webpack.config.cjs index a3733a86..f62651f4 100644 --- a/webpack.config.cjs +++ b/webpack.config.cjs @@ -10,6 +10,7 @@ const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' ); const SCHEMA_SRC = './schema/schema.json'; const SCHEMA_OUTPUT_NAME = 'schema.json'; +const SCHEMA_SRC_PATH = path.resolve( __dirname, SCHEMA_SRC ); module.exports = function ( env ) { let targets = [ 'firefox', 'chrome' ]; @@ -70,6 +71,10 @@ function extensionModules( mode, target ) { ], }; + const watchOptions = { + ignored: [ SCHEMA_SRC_PATH ], + }; + const webExtensionPolyfillPlugin = new webpack.ProvidePlugin( { browser: 'webextension-polyfill', } ); @@ -108,6 +113,7 @@ function extensionModules( mode, target ) { webExtensionPolyfillPlugin, envPlugin, ], + watchOptions, }, // Extension content script. { @@ -121,6 +127,7 @@ function extensionModules( mode, target ) { filename: path.join( 'content.js' ), }, plugins: [ webExtensionPolyfillPlugin, envPlugin ], + watchOptions, }, // The app. { @@ -180,6 +187,7 @@ function extensionModules( mode, target ) { ].concat( mode === 'production' ? [ new MiniCssExtractPlugin() ] : [] ), + watchOptions, }, ]; } From b161bd005dc77b93b3d841c6a931b5f63daac073 Mon Sep 17 00:00:00 2001 From: ashfame Date: Wed, 11 Dec 2024 19:03:47 +0400 Subject: [PATCH 5/6] use defined constants --- webpack.config.cjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webpack.config.cjs b/webpack.config.cjs index f62651f4..4740608f 100644 --- a/webpack.config.cjs +++ b/webpack.config.cjs @@ -157,11 +157,11 @@ function extensionModules( mode, target ) { to: path.join( targetPath, 'plugin' ), }, { - from: './schema/schema.json', + from: SCHEMA_SRC, to: path.join( targetPath, 'plugin', - 'schema.json' + SCHEMA_OUTPUT_NAME ), }, ], From ccda522712a01e6e69aa66979624c19dc549d299 Mon Sep 17 00:00:00 2001 From: ashfame Date: Wed, 11 Dec 2024 19:15:59 +0400 Subject: [PATCH 6/6] remove unused import --- webpack.config.cjs | 1 - 1 file changed, 1 deletion(-) diff --git a/webpack.config.cjs b/webpack.config.cjs index 4740608f..20076fc9 100644 --- a/webpack.config.cjs +++ b/webpack.config.cjs @@ -1,4 +1,3 @@ -const fs = require( 'fs' ); const { readFileSync } = require( 'node:fs' ); const path = require( 'node:path' ); const { execSync } = require( 'child_process' );