Plugins: Pass build mode to frontend (#114092)

* pass build mode to frontend

* set buildMode build time using shared plugin webpack conf
This commit is contained in:
Erik Sundell
2025-11-19 15:42:27 +01:00
committed by GitHub
parent acf6f1ae5f
commit be0857fa8f
5 changed files with 39 additions and 1 deletions
@@ -37,6 +37,7 @@ export type AppPluginConfig = {
dependencies: PluginDependencies;
extensions: PluginExtensions;
moduleHash?: string;
buildMode?: string;
};
export type PreinstalledPlugin = {
@@ -4,7 +4,7 @@ import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import path from 'path';
import ReplaceInFileWebpackPlugin from 'replace-in-file-webpack-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import webpack, { type Configuration } from 'webpack';
import webpack, { type Configuration, type Compiler } from 'webpack';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import VirtualModulesPlugin from 'webpack-virtual-modules';
@@ -31,6 +31,36 @@ function skipFiles(f: string): boolean {
return true;
}
class BuildModeWebpackPlugin {
apply(compiler: Compiler) {
compiler.hooks.compilation.tap('BuildModeWebpackPlugin', (compilation) => {
compilation.hooks.processAssets.tap(
{
name: 'BuildModeWebpackPlugin',
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
},
async () => {
const assets = compilation.getAssets();
for (const asset of assets) {
if (asset.name.endsWith('plugin.json')) {
const pluginJsonString = asset.source.source().toString();
const pluginJsonWithBuildMode = JSON.stringify(
{
...JSON.parse(pluginJsonString),
buildMode: compilation.options.mode,
},
null,
4
);
compilation.updateAsset(asset.name, new webpack.sources.RawSource(pluginJsonWithBuildMode));
}
}
}
);
});
}
}
export type Env = {
[key: string]: true | string | Env;
};
@@ -253,6 +283,8 @@ const config = async (env: Env): Promise<Configuration> => {
],
},
]),
// Add buildMode to plugin.json
new BuildModeWebpackPlugin(),
...(env.development
? [
new ForkTsCheckerWebpackPlugin({
+1
View File
@@ -637,6 +637,7 @@ func (hs *HTTPServer) newAppDTO(ctx context.Context, plugin pluginstore.Plugin,
Dependencies: plugin.Dependencies,
ModuleHash: hs.pluginAssets.ModuleHash(ctx, plugin),
Translations: plugin.Translations,
BuildMode: plugin.BuildMode,
}
if settings.Enabled {
+1
View File
@@ -339,6 +339,7 @@ type AppDTO struct {
Dependencies Dependencies `json:"dependencies"`
ModuleHash string `json:"moduleHash,omitempty"`
Translations map[string]string `json:"translations,omitempty"`
BuildMode string `json:"buildMode,omitempty"`
}
const (
+3
View File
@@ -133,6 +133,9 @@ type JSONData struct {
// List of languages supported by the plugin
Languages []string `json:"languages,omitempty"`
// Build mode of the plugin (set automatically at build time)
BuildMode string `json:"buildMode,omitempty"`
}
func ReadPluginJSON(reader io.Reader) (JSONData, error) {