module-builder icon indicating copy to clipboard operation
module-builder copied to clipboard

provide option to copy along static files

Open tobiasdiez opened this issue 1 year ago • 5 comments

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.

tobiasdiez avatar Nov 11 '22 23:11 tobiasdiez

Does it works if you put it inside src/runtime/static?

pi0 avatar Nov 14 '22 11:11 pi0

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 avatar Jan 17 '23 08:01 harlan-zw

@harlan-zw Nice. That would be a nice kit utility candidate.

pi0 avatar Jan 17 '23 11:01 pi0

@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 explicit dst, otherwise it keeps the .template extension. But explicit dst means the filename.[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 into dist/assets (then it's up to the developer how to use it).

IlyaSemenov avatar May 21 '23 02:05 IlyaSemenov

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

pi0 avatar May 24 '23 10:05 pi0