Package Exports
- cachebust-es6-imports-cli
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cachebust-es6-imports-cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
cachebust-es6-imports-cli
Install: npm i cachebust-es6-imports-cli -D
cachebust-es6-imports-cli is a command line app that allows you to cachebust es6 imports. It is intended to be used in conjuction with the laren cli tool.
For example, cachebust-es6-imports-cli will take the following js file:
import { Thing } from "./index.js";
console.log('hi from index.js');
and convert it to:
import { Thing } from "./index_HILQ1xmt0EvHZnXdypa0.js";
console.log('hi from index.js');
The cache bust string is set via the environment variable CACHE_BUST_STRING. You would set this in your npm task.
Here is an example of how you would use this via npm scripts:
"build": "CACHE_BUST_STRING=$(random string) NODE_ENV=production run-s build:**",
"build:clean": "trash dist && mkdir dist",
"build:copy-assets": "ncp src/css dist/css && ncp src/js dist/js",
"build:cachebust-js-files": "laren \"./dist/js/**/*.js\" \"f => f.replace('.js', '_' + process.env.CACHE_BUST_STRING + '.js')\"",
"build:cachebust-js-file-imports": "cachebust-es6-imports-cli --glob \"./dist/js/**/*.js\"",So in the example above, we use laren to rename the .js files in the dist folder, then we use cachebust-es6-imports-cli to rename the imports so they match up to the changed file names. (This of course assumes that you are moving your source files to a dist folder before you change the names).
Note: the cache bust string does not represent a hash of the javascript file. It is just a random string.
Usage: cachebust-es6-imports-cli [options]
Options:
-g, --glob <glob> File glob
-h, --help display help for command
Other links
- random-generator-cli - generate random text
- Laren - rename files on the command line
- html-script-src-replace - rename an html script src attribute value using the
CACHE_BUST_STRING - babel-plugin-transform-rename-import