生成Nuxt.js/Vue.js中的最小化公共JavaScript。

huangapple go评论65阅读模式
英文:

Generate minified public javascript in Nuxt.js/Vue.js

问题

我们有一个相对标准的Nuxt.js应用程序,使用Nitro的“firebase”预设部署到Firebase托管。

除了构成应用程序本身的JavaScript之外,我们还有一个位于public/embed.js中的文件,旨在供第三方引用(用于在其网站上嵌入小部件)。

我希望在构建过程中对embed.js文件进行压缩/缩小,以便任何请求它的人都会收到一个缩小的版本。目前,该文件似乎只是从public/embed.js复制到.output/public目录,没有进行修改。

这是否可以通过配置选项来完成,如果可以,如何实现?

英文:

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?

答案1

得分: 1

你可以添加一个脚本来压缩你的文件,然后像这样与构建脚本一起运行它:

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

但是如果你的 embed.js 很少改动,你只需要手动压缩它,然后放入 public 文件夹中。

英文:

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

huangapple
  • 本文由 发表于 2023年6月9日 01:31:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76434352.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定