Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy assets from NPM

I'm trying to use font-awesome with npm but with the newest version (>4) I'm having difficulty finding the fonts directory.

Before, I was using a npm script like cp -R ./node_modules/font-awesome/fonts/* dist/assets/ but this doesn't work anymore when my library is used by a program that will regroup all the modules at the root directory.

Is there a safe method to know where they are or any other trick that could achieve the same goal?

Thanks

like image 660
NorTicUs Avatar asked Nov 01 '25 01:11

NorTicUs


1 Answers

I found a solution: I implemented an npm utility to output node_module's path https://github.com/lexoyo/node_modules-path

It just registers as a ".bin" script to be accessible in npm scripts, and the output is Path.resolve(__dirname, '..');.

So you can use this in your package.json or shell scripts:

$ mkdir -p dist/fonts
$ cp -R `node_modules`/font-awesome/fonts/* dist/fonts/"

The script exports the NODE_MODULES env var so you should be able to use it like this, but I did not test it:

$ mkdir -p dist/fonts
$ node_modules
$ cp -R ${NODE_MODULES}/font-awesome/fonts/* dist/fonts/"
like image 63
lexa Avatar answered Nov 03 '25 15:11

lexa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!