Supporting multri entry
This commit is contained in:
28
src/index.ts
28
src/index.ts
@@ -64,8 +64,9 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
|
||||
let htmlModules = new Map<string, HtmlModule>();// todo clean this per new build?
|
||||
let virtualSources = new Map<string, string>();
|
||||
|
||||
const pluginName = 'html2';
|
||||
return {
|
||||
name: 'html2',// TODO: Need a better name, original plugin was just named `html` and might still make sense to use in conjunction with this one
|
||||
name: pluginName,// TODO: Need a better name, original plugin was just named `html` and might still make sense to use in conjunction with this one
|
||||
|
||||
resolveId: {
|
||||
async handler(specifier: string,
|
||||
@@ -95,6 +96,13 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
|
||||
|
||||
htmlModules.set(htmlModule.id, htmlModule);
|
||||
// TODO: trigger special handling when imported from a JS file (in which case we want might want to export a module returning the HTML, instead of HTML directly)
|
||||
return {
|
||||
...resolved,
|
||||
meta: {
|
||||
...resolved.meta,
|
||||
[pluginName]: {name: specifier}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -132,20 +140,18 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
|
||||
sourceId = makeInlineId(id, node, 'js');
|
||||
}
|
||||
if(source){
|
||||
virtualSources.set(sourceId, source);// TODO actually loading in the virtual source (if any)
|
||||
virtualSources.set(sourceId, source);
|
||||
}
|
||||
|
||||
const resolved = await this.resolve(sourceId, id, {
|
||||
isEntry: type==='entryChunk',
|
||||
});
|
||||
// if(!resolved){
|
||||
// throw new Error(`Could not resolve ${sourceId} from ${id}`);
|
||||
// }
|
||||
// const loaded = await this.load({
|
||||
// id: sourceId,
|
||||
// resolveDependencies: true,
|
||||
// moduleSideEffects: 'no-treeshake'
|
||||
// });
|
||||
if(!resolved){
|
||||
throw new Error(`Could not resolve ${sourceId} from ${id}`);
|
||||
}
|
||||
|
||||
const selfInfo = this.getModuleInfo(id);
|
||||
const importName = (source && selfInfo?.meta[pluginName].name) ? makeInlineId(selfInfo?.meta[pluginName].name, node, extname(sourceId)) : undefined;
|
||||
|
||||
const htmlImport: HtmlImport = {
|
||||
id: <string>sourceId,
|
||||
@@ -158,6 +164,7 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
|
||||
(resolved && (['chunk','entryChunk'].includes(type!))) ? this.emitFile({
|
||||
type: 'chunk', // Might want to adapt, or make configurable (see LoadType)
|
||||
id: resolved.id,
|
||||
name: importName,
|
||||
importer: id,
|
||||
}) : null,
|
||||
placeholder: `html-import-${crypto.randomBytes(32).toString('base64')}`,
|
||||
@@ -198,6 +205,7 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO when importing html from .js this will not do. (
|
||||
const htmlJSModule = [
|
||||
...moduleImports,
|
||||
``,
|
||||
|
||||
Reference in New Issue
Block a user