英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论