adding src

This commit is contained in:
∇ince
2025-01-19 01:49:53 -08:00
parent 3edbb5e2cc
commit 6e1cdd4d30
11 changed files with 6473 additions and 0 deletions
@@ -0,0 +1,37 @@
class HtmlWorkerScriptPlugin {
apply(compiler) {
compiler.hooks.compilation.tap('HtmlWorkerScriptPlugin', (compilation) => {
// Hook into HtmlWebpackPlugin's emit stage
const HtmlWebpackPlugin = compiler.options.plugins.find((plugin) => plugin.constructor.name === 'HtmlWebpackPlugin');
if (HtmlWebpackPlugin) {
HtmlWebpackPlugin.constructor.getHooks(compilation).beforeEmit.tapAsync('HtmlWorkerScriptPlugin', (data, callback) => {
console.log('HtmlWorkerScriptPlugin modifying HTML asset');
const jsAsset = compilation.assets['index.js'];
if (jsAsset) {
const jsCode = jsAsset.source();
// Append inline script to the end of the html
data.html += `\n<script type="text/worker">${jsCode}</script>`;
// Replace placeholders and clean up
const currentDate = new Date().toUTCString();
data.html = data.html.replace('$$CURRENTRELEASEDATE$$', currentDate);
if (process.env.NODE_ENV === 'production') {
data.html = data.html.replace(/^\s*<!--DEVELOPMENT CODE\. NOT READY FOR PRODUCTION YET-->\s*\r?\n?/gm, '');
}
} else {
console.error('HtmlWorkerScriptPlugin: JavaScript asset not found.');
}
callback(null, data);
});
} else {
console.error('HtmlWorkerScriptPlugin: HtmlWebpackPlugin not found.');
}
});
}
}
module.exports = HtmlWorkerScriptPlugin;