Implement JQHTML function cache ID system and fix bundle compilation Implement underscore prefix for system tables Fix JS syntax linter to support decorators and grant exception to Task system SPA: Update planning docs and wishlists with remaining features SPA: Document Navigation API abandonment and future enhancements Implement SPA browser integration with History API (Phase 1) Convert contacts view page to SPA action Convert clients pages to SPA actions and document conversion procedure SPA: Merge GET parameters and update documentation Implement SPA route URL generation in JavaScript and PHP Implement SPA bootstrap controller architecture Add SPA routing manual page (rsx:man spa) Add SPA routing documentation to CLAUDE.md Phase 4 Complete: Client-side SPA routing implementation Update get_routes() consumers for unified route structure Complete SPA Phase 3: PHP-side route type detection and is_spa flag Restore unified routes structure and Manifest_Query class Refactor route indexing and add SPA infrastructure Phase 3 Complete: SPA route registration in manifest Implement SPA Phase 2: Extract router code and test decorators Rename Jqhtml_Component to Component and complete SPA foundation setup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
149 lines
4.1 KiB
JavaScript
149 lines
4.1 KiB
JavaScript
/*
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
Author Tobias Koppers @sokra
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
const { ConcatSource, RawSource } = require("webpack-sources");
|
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
const Template = require("../Template");
|
|
const { getUndoPath } = require("../util/identifier");
|
|
const {
|
|
createChunkHashHandler,
|
|
getChunkInfo
|
|
} = require("./ChunkFormatHelpers");
|
|
const {
|
|
getChunkFilenameTemplate,
|
|
getCompilationHooks
|
|
} = require("./JavascriptModulesPlugin");
|
|
const { generateEntryStartup } = require("./StartupHelpers");
|
|
|
|
/** @typedef {import("../Chunk")} Chunk */
|
|
/** @typedef {import("../Compiler")} Compiler */
|
|
|
|
const PLUGIN_NAME = "CommonJsChunkFormatPlugin";
|
|
|
|
class CommonJsChunkFormatPlugin {
|
|
/**
|
|
* Apply the plugin
|
|
* @param {Compiler} compiler the compiler instance
|
|
* @returns {void}
|
|
*/
|
|
apply(compiler) {
|
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
compilation.hooks.additionalChunkRuntimeRequirements.tap(
|
|
PLUGIN_NAME,
|
|
(chunk, set, { chunkGraph }) => {
|
|
if (chunk.hasRuntime()) return;
|
|
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) {
|
|
set.add(RuntimeGlobals.require);
|
|
set.add(RuntimeGlobals.startupEntrypoint);
|
|
set.add(RuntimeGlobals.externalInstallChunk);
|
|
}
|
|
}
|
|
);
|
|
const hooks = getCompilationHooks(compilation);
|
|
hooks.renderChunk.tap(PLUGIN_NAME, (modules, renderContext) => {
|
|
const { chunk, chunkGraph, runtimeTemplate } = renderContext;
|
|
const source = new ConcatSource();
|
|
source.add(`exports.id = ${JSON.stringify(chunk.id)};\n`);
|
|
source.add(`exports.ids = ${JSON.stringify(chunk.ids)};\n`);
|
|
source.add("exports.modules = ");
|
|
source.add(modules);
|
|
source.add(";\n");
|
|
const runtimeModules = chunkGraph.getChunkRuntimeModulesInOrder(chunk);
|
|
if (runtimeModules.length > 0) {
|
|
source.add("exports.runtime =\n");
|
|
source.add(
|
|
Template.renderChunkRuntimeModules(runtimeModules, renderContext)
|
|
);
|
|
}
|
|
const { entries, runtimeChunk } = getChunkInfo(chunk, chunkGraph);
|
|
if (runtimeChunk) {
|
|
const currentOutputName = compilation
|
|
.getPath(
|
|
getChunkFilenameTemplate(chunk, compilation.outputOptions),
|
|
{
|
|
chunk,
|
|
contentHashType: "javascript"
|
|
}
|
|
)
|
|
.replace(/^\/+/g, "")
|
|
.split("/");
|
|
const runtimeOutputName = compilation
|
|
.getPath(
|
|
getChunkFilenameTemplate(
|
|
/** @type {Chunk} */
|
|
(runtimeChunk),
|
|
compilation.outputOptions
|
|
),
|
|
{
|
|
chunk: /** @type {Chunk} */ (runtimeChunk),
|
|
contentHashType: "javascript"
|
|
}
|
|
)
|
|
.replace(/^\/+/g, "")
|
|
.split("/");
|
|
|
|
// remove common parts
|
|
while (
|
|
currentOutputName.length > 1 &&
|
|
runtimeOutputName.length > 1 &&
|
|
currentOutputName[0] === runtimeOutputName[0]
|
|
) {
|
|
currentOutputName.shift();
|
|
runtimeOutputName.shift();
|
|
}
|
|
const last = runtimeOutputName.join("/");
|
|
// create final path
|
|
const runtimePath =
|
|
getUndoPath(currentOutputName.join("/"), last, true) + last;
|
|
|
|
const entrySource = new ConcatSource();
|
|
entrySource.add(
|
|
`(${
|
|
runtimeTemplate.supportsArrowFunction() ? "() => " : "function() "
|
|
}{\n`
|
|
);
|
|
entrySource.add("var exports = {};\n");
|
|
entrySource.add(source);
|
|
entrySource.add(";\n\n// load runtime\n");
|
|
entrySource.add(
|
|
`var ${RuntimeGlobals.require} = require(${JSON.stringify(
|
|
runtimePath
|
|
)});\n`
|
|
);
|
|
entrySource.add(`${RuntimeGlobals.externalInstallChunk}(exports);\n`);
|
|
const startupSource = new RawSource(
|
|
generateEntryStartup(
|
|
chunkGraph,
|
|
runtimeTemplate,
|
|
entries,
|
|
chunk,
|
|
false
|
|
)
|
|
);
|
|
entrySource.add(
|
|
hooks.renderStartup.call(
|
|
startupSource,
|
|
entries[entries.length - 1][0],
|
|
{
|
|
...renderContext,
|
|
inlined: false
|
|
}
|
|
)
|
|
);
|
|
entrySource.add("\n})()");
|
|
return entrySource;
|
|
}
|
|
return source;
|
|
});
|
|
|
|
hooks.chunkHash.tap(PLUGIN_NAME, createChunkHashHandler(PLUGIN_NAME));
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = CommonJsChunkFormatPlugin;
|