I was looking to do the exact same thing today and this is the most relevant and number one hit on google.
The example by Gangstead is correct but incomplete, when somebody asks this type of question they likely need a complete answer, and possibly even some context and explanation.
Here is the full solution:
package.json:
{
"name": "abridge-bundle",
"version": "1.1.0",
"description": "Abridge - bundle and minify js",
"author": "Jake G <[email protected]>",
"license": "MIT",
"homepage": "https://github.com/Jieiku/abridge",
"scripts": {
"uglify": "uglifyjs public/search_index.en.js public/elasticlunr.min.js public/search.js -c -m -o static/search_bundle.min.js"
},
"dependencies": {
"uglify-js": "^3.15.4"
}
}
The above package.json file can be used to generate minified js file by typing npm run uglify.
In my case I deploy to netlify, so here is the netlify.toml as well:
[build]
publish = "public"
command = "zola build && npm run uglify"
[build.environment]
ZOLA_VERSION = "0.16.0"
[context.deploy-preview]
command = "zola build --base-url $DEPLOY_PRIME_URL && npm run uglify"
[[headers]]
for = "/*"
[headers.values]
X-Frame-Options = "DENY"
X-Content-Type-Options = "nosniff"
X-XSS-Protection = "1; mode=block"
Referrer-Policy = "strict-origin-when-cross-origin"
Strict-Transport-Security = "max-age=63072000; includeSubdomains"
Content-Security-Policy = "default-src 'none'; frame-ancestors 'none'; object-src 'none'; base-uri 'self'; manifest-src 'self'; connect-src 'self'; form-action 'self'; script-src 'self'; img-src 'self' data: cdn.cloudflare.com; frame-src 'self' www.youtube-nocookie.com player.vimeo.com; media-src 'self' data: cdn.cloudflare.com www.youtube-nocookie.com player.vimeo.com; font-src 'self' cdn.cloudflare.com cdn.jsdelivr.net fonts.gstatic.com; style-src 'self' 'unsafe-inline' cdn.cloudflare.com cdn.jsdelivr.net fonts.googleapis.com;"
These are currently viewable at my repository as well (zola static site generator theme): https://github.com/Jieiku/abridge