module-builder
module-builder copied to clipboard
provide option to copy along static files
Sometimes you want to copy static files (in my case a ts file that servers as the source for addTemplate
). This currently doesn't seem to be possible.
Does it works if you put it inside src/runtime/static
?
Doing this worked for me
nuxt.hooks.hook('nitro:config', (nitroConfig) => {
nitroConfig.publicAssets = nitroConfig.publicAssets || []
nitroConfig.publicAssets.push({ dir: resolve('./runtime/public'), maxAge: 31536000 })
})
@harlan-zw Nice. That would be a nice kit utility candidate.
@pi0:
Does it works if you put it inside
src/runtime/static
?
Not really. template.ts
is copied but it's transformed into the pair of .mjs
and .d.ts
which is not desireable (in particular, that means addTemplate
calls should be different between dev and production).
One could work around that by using non-ts extension (such as .ts.template
) but then:
- The file is not recognized by IDE (unless manually fiddled).
-
addTemplate
needs explicitdst
, otherwise it keeps the.template
extension. But explicitdst
means thefilename.[hash].ts
mechanism is not used.
All and all, that's not really an option. We need a way to copy over certain files verbatim.
Suggestions:
- Treat
.template.ts
as an exception for transformation. - Copy the entire
src/assets
intodist/assets
(then it's up to the developer how to use it).
I think you still can use a top level directory and include it in package.json files without transforms (dist and src having same relative path) but sure supporting an assets
type could be nice option.
Upstream: https://github.com/unjs/unbuild/issues/266