0.0.5: fix, try to resolve sensible entrynames even if files were imported with an absolute path
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
ba09aaf915
commit
48dcdefee1
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rollup-plugin-html-entry2",
|
||||
"version": "0.0.4",
|
||||
"version": "0.0.5",
|
||||
"description": "Teaches rollup how to deal with HTML, allows to use HTML-files as entry-points.",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
|
||||
22
src/index.ts
22
src/index.ts
@ -66,11 +66,17 @@ 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>();
|
||||
let addedEntries = new Map<string, string>();
|
||||
let entryNames = new Map<string,string>();
|
||||
|
||||
const pluginName = 'html2';
|
||||
return {
|
||||
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
|
||||
|
||||
buildStart(options){
|
||||
entryNames = new Map(Object.entries(typeof(options.input)==='object'?options.input:{[options.input]:[options.input]})
|
||||
.map(([k,v])=>[v,k])
|
||||
);
|
||||
},
|
||||
resolveId: {
|
||||
async handler(specifier: string,
|
||||
importer: string | undefined,
|
||||
@ -146,12 +152,6 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
|
||||
if(source){
|
||||
virtualSources.set(sourceId, source);
|
||||
}
|
||||
let entryName: string|undefined = undefined;
|
||||
if(type==='entryChunk'){
|
||||
entryName= posix.join(posix.dirname(htmlModule.name),sourceId);
|
||||
entryName = entryName.slice(0,-(posix.extname(entryName).length)); // Cut off the extension (TODO, is this wise?)
|
||||
}
|
||||
|
||||
const resolved = await this.resolve(sourceId, id, {
|
||||
isEntry: type==='entryChunk',
|
||||
});
|
||||
@ -160,8 +160,16 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
|
||||
}
|
||||
|
||||
const selfInfo = this.getModuleInfo(id);
|
||||
|
||||
let entryName: string|undefined = undefined;
|
||||
const parentName = entryNames.get(id)??selfInfo?.meta[pluginName].name;
|
||||
if(type==='entryChunk'){
|
||||
entryName= posix.join(posix.dirname(parentName),sourceId);
|
||||
entryName = entryName.slice(0,-(posix.extname(entryName).length)); // Cut off the extension (TODO, is this wise?)
|
||||
}
|
||||
|
||||
const importName = (source && selfInfo?.meta[pluginName].name)
|
||||
? makeInlineId(selfInfo?.meta[pluginName].name, node, extname(sourceId))
|
||||
? makeInlineId(parentName, node, extname(sourceId))
|
||||
: entryName;
|
||||
|
||||
const htmlImport: HtmlImport = {
|
||||
|
||||
@ -39,6 +39,12 @@ Generated by [AVA](https://avajs.dev).
|
||||
map: undefined,
|
||||
source: '{"version":3,"file":"batman-c7fa228c.js","sources":["../../admin/batman.js"],"sourcesContent":["export const b = ()=>\'batman\';\\nconsole.log(b());\\n"],"names":[],"mappings":"AAAY,MAAC,CAAC,GAAG,IAAI,SAAS;AAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;;;;"}',
|
||||
},
|
||||
{
|
||||
code: undefined,
|
||||
fileName: 'admin/index.body.script0.js-15dfaff3.js.map',
|
||||
map: undefined,
|
||||
source: '{"version":3,"file":"index.body.script0.js-15dfaff3.js","sources":["../../app/admin-deps.js","../../admin/index.html.body.script0.js"],"sourcesContent":["export function adminDeps(){\\n return \\"robin!\\";\\n}\\n","\\n import {bootstrap} from \\"../app/app.js\\"\\n import {adminDeps} from \\"../app/admin-deps.js\\";\\n bootstrap(document.getElementById(\'root\'), adminDeps());\\n "],"names":[],"mappings":";;AAAO,SAAS,SAAS,EAAE;AAC3B,IAAI,OAAO,QAAQ,CAAC;AACpB;;ACCY,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC"}',
|
||||
},
|
||||
{
|
||||
code: undefined,
|
||||
fileName: 'admin/index.html',
|
||||
@ -54,19 +60,13 @@ Generated by [AVA](https://avajs.dev).
|
||||
}␊
|
||||
␊
|
||||
bootstrap(document.getElementById('root'), adminDeps());␊
|
||||
//# sourceMappingURL=index.html.body.script0.js-15dfaff3.js.map␊
|
||||
//# sourceMappingURL=index.body.script0.js-15dfaff3.js.map␊
|
||||
</script>␊
|
||||
<script src="batman-c7fa228c.js" type="module"></script>␊
|
||||
␊
|
||||
␊
|
||||
</body></html>`,
|
||||
},
|
||||
{
|
||||
code: undefined,
|
||||
fileName: 'admin/index.html.body.script0.js-15dfaff3.js.map',
|
||||
map: undefined,
|
||||
source: '{"version":3,"file":"index.html.body.script0.js-15dfaff3.js","sources":["../../app/admin-deps.js","../../admin/index.html.body.script0.js"],"sourcesContent":["export function adminDeps(){\\n return \\"robin!\\";\\n}\\n","\\n import {bootstrap} from \\"../app/app.js\\"\\n import {adminDeps} from \\"../app/admin-deps.js\\";\\n bootstrap(document.getElementById(\'root\'), adminDeps());\\n "],"names":[],"mappings":";;AAAO,SAAS,SAAS,EAAE;AAC3B,IAAI,OAAO,QAAQ,CAAC;AACpB;;ACCY,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC"}',
|
||||
},
|
||||
{
|
||||
code: `const bootstrap = (el,deps = [])=>{␊
|
||||
el.innerHtml = \`␊
|
||||
|
||||
Binary file not shown.
@ -1,4 +1,4 @@
|
||||
import {join, dirname} from "node:path";
|
||||
import {resolve, join, dirname} from "node:path";
|
||||
|
||||
import test from "ava";
|
||||
import { rollup } from "rollup";
|
||||
@ -21,7 +21,7 @@ test.serial('multi-entry', async (t) => {
|
||||
const bundle = await rollup({
|
||||
input: {
|
||||
['index']: 'index.html',
|
||||
['admin/index']: 'admin/index.html'
|
||||
['admin/index']: resolve(__dirname,'fixtures','admin/index.html'),
|
||||
},
|
||||
plugins: [
|
||||
html({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user