mentaljam / rollup-plugin-html2

Rollup plugin to inject bundled files to an HTML template
https://www.npmjs.com/package/rollup-plugin-html2
MIT License
20 stars 5 forks source link

Different behavior between watch/non-watch mode #19

Closed tswaters closed 7 months ago

tswaters commented 7 months ago

In watch mode, seems to work OK.

In non-watch mode, I'm getting this error -

[!] (plugin html2) RollupError: The input template doesn't contain the html tag

This is with 4.12.0 (previously was working on v2 and works fine there)

It looks like this line tries to cache whether the template is a file,

this.cache.set("templateIsFile" /* templateIsFile */, templateIsFile);

Later, in generateBundle function,

const data = this.cache.get("templateIsFile" /* templateIsFile */)
            ? fs.readFileSync(template).toString()
            : template;

this.cache.get("templateIsFile" /* templateIsFile */) is returning undefined, so it thinks the provided template parameter is the string of the template instead of a file... I'm not sure when this changed but I'm trying to update dependencies and hit this issue.

tswaters commented 7 months ago

Oh, turns out I need to pass cache: true into the rollup config options, otherwise it'll use NO_CACHE implementation, and this.cache.get calls will all return undefined. Interesting design... shame it's not mentioned in the changelog as far as I can tell.

This can be closed I think? Might be good to add a note to the readme.

tswaters commented 7 months ago

I'm a dummy.... I was using v2.0.0 of rollup-plugin-html2 -- updating to version 4 and I don't see the same issue.

tswaters commented 7 months ago

ERR, truly a dummy -- I tried it again under v4 w/out cache and didn't see the same problem... .never tried build.

Must pass cache: true as a root rollup option for this to work properly.