hardcode assembles a virtual, import-able file system from disk.
npm i hardcode
The package comes with a built-in CLI for build scripts:
hardcode <glob> --out <out> --prefix <prefix>
See hardcode --help for more details.
Add hardcode <glob> to your build script. For example:
...
"build": "hardcode <pattern> && jest"
...
- Imagine that you have the following files on disk:
templates/
dev/
email.html
res/
style.css
- Now, run
hardcodeon thetemplates/devdirectory.
consthardcode=require('hardcode');hardcode({pattern: 'templates/dev/**',prefix: 'templates/dev/',out: 'templates/import/'});- Finally, import the
templates/devdirectory as a JSON object:
consttemplates=require('./templates/import')consthtml=templates['email.html']// email.html file contentsconstcss=templates['res']['style.css']// style.css file contentsThis code is licensed under GNU-GPLv3.