diff --git a/packages/snaps-execution-environments/package.json b/packages/snaps-execution-environments/package.json
index 1ab182b993..cc240c5630 100644
--- a/packages/snaps-execution-environments/package.json
+++ b/packages/snaps-execution-environments/package.json
@@ -116,7 +116,8 @@
"vite-tsconfig-paths": "^4.0.5",
"vitest": "^3.1.1",
"webpack": "^5.97.1",
- "webpack-merge": "^5.9.0"
+ "webpack-merge": "^5.9.0",
+ "webpack-sources": "^3.3.3"
},
"engines": {
"node": "^20 || >=22"
diff --git a/packages/snaps-execution-environments/src/index.ejs b/packages/snaps-execution-environments/src/index.ejs
index 4ccd2c647b..6a799ae712 100644
--- a/packages/snaps-execution-environments/src/index.ejs
+++ b/packages/snaps-execution-environments/src/index.ejs
@@ -4,7 +4,9 @@
MetaMask Snaps Execution Environment
+ <% if (typeof lockdownScript !== 'undefined') { %>
+ <% } %>
<% if (typeof inlineSource !== 'undefined') { %>
diff --git a/packages/snaps-execution-environments/webpack.config.js b/packages/snaps-execution-environments/webpack.config.js
index ebce9e9961..23366f57cb 100644
--- a/packages/snaps-execution-environments/webpack.config.js
+++ b/packages/snaps-execution-environments/webpack.config.js
@@ -10,6 +10,7 @@ const { resolve } = require('path');
const { TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin');
const { ProvidePlugin, Compilation } = require('webpack');
const { merge } = require('webpack-merge');
+const { RawSource } = require('webpack-sources');
/**
* Whether to generate a policy file for the build.
@@ -64,11 +65,6 @@ const DEFAULT_WEB_CONFIG = {
plugins: [
new HtmlWebpackPlugin({
template: './src/index.ejs',
- templateParameters: () => {
- return {
- lockdownScript: SES_BUNDLE,
- };
- },
}),
],
};
@@ -272,6 +268,45 @@ const configs = ENTRY_POINTS.map(
});
},
},
+
+ {
+ /**
+ * A custom plugin to add SES to the build.
+ *
+ * @param {import('webpack').Compiler} compiler - The Webpack compiler.
+ */
+ apply(compiler) {
+ const PLUGIN_NAME = 'AddSESPlugin';
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
+ compilation.hooks.processAssets.tap(
+ {
+ name: PLUGIN_NAME,
+ stage: compilation.PROCESS_ASSETS_STAGE_REPORT,
+ },
+ () => {
+ compilation.emitAsset('ses.js', new RawSource(SES_BUNDLE), {
+ minimized: true,
+ });
+ },
+ );
+
+ HtmlWebpackPlugin.getHooks(
+ compilation,
+ ).alterAssetTagGroups.tapAsync(PLUGIN_NAME, (data, callback) => {
+ // Add the SES script tag to the HTML files.
+ data.headTags.unshift({
+ tagName: 'script',
+ voidTag: false,
+ attributes: {
+ src: 'ses.js',
+ },
+ });
+
+ callback(null, data);
+ });
+ });
+ },
+ },
],
}),
);
diff --git a/yarn.lock b/yarn.lock
index 522bbd4933..e8682573c1 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4376,6 +4376,7 @@ __metadata:
vitest: "npm:^3.1.1"
webpack: "npm:^5.97.1"
webpack-merge: "npm:^5.9.0"
+ webpack-sources: "npm:^3.3.3"
languageName: unknown
linkType: soft
@@ -18875,10 +18876,10 @@ __metadata:
languageName: node
linkType: hard
-"webpack-sources@npm:^3.2.3":
- version: 3.2.3
- resolution: "webpack-sources@npm:3.2.3"
- checksum: 10/a661f41795d678b7526ae8a88cd1b3d8ce71a7d19b6503da8149b2e667fc7a12f9b899041c1665d39e38245ed3a59ab68de648ea31040c3829aa695a5a45211d
+"webpack-sources@npm:^3.2.3, webpack-sources@npm:^3.3.3":
+ version: 3.3.3
+ resolution: "webpack-sources@npm:3.3.3"
+ checksum: 10/ec5d72607e8068467370abccbfff855c596c098baedbe9d198a557ccf198e8546a322836a6f74241492576adba06100286592993a62b63196832cdb53c8bae91
languageName: node
linkType: hard