0

We have a relatively boilerplate Nuxt.js application, deployed with the "firebase" preset of Nitro to Firebase hosting.

In addition to the JavaScript that makes up the application itself, we have a file in public/embed.js that is intended to be referenced by third parties (it is used to facilitate embedding of a widget on their website).

I would like the embed.js file to be tersed/minified during the build process, so that anyone that requests it receives a minified version. Currently, the file seems to be copied from public/embed.js to the .output/public directory without modification.

Can this be done with configuration options, and if so, how?

Myk Willis
  • 12,306
  • 4
  • 45
  • 62

1 Answers1

1

You can add a script to minify your file and run it along with your build script like this:

// package.json
{
  "scripts": {
    "minify-embed": "uglifyjs public/embed.js",
    "build": "yarn minify-embed && yarn build:client && yarn build:server",
  }
}

But if your embed.js is rarely changed, you just need to manually minify it and then put it in the public folder

Duannx
  • 7,501
  • 1
  • 26
  • 59
  • 1
    I was hoping there was some kind of nuxt/vite config that would allow me to do this declaratively as part of then normal build. That said, just running an extra step during build to do the minify is a pretty simple solution for this basic use case. – Myk Willis Jun 09 '23 at 15:41