Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using npm scripts to Inject *.js and *.css into index.html

I´m looking into switch from gulp/grunt to only use npm scripts. But I cant really solve how to get *.js and *.css from a given path and add it to the index.html file.

must I add it thru a "index.js" file or can I do something like...

"scripts": {
 "inject": "inject src/app/*.js",
},

and then it will add it in my index.html where I have specified it like...

/* inject:js */
like image 945
Mackelito Avatar asked Feb 21 '16 21:02

Mackelito


People also ask

How do I put JavaScript and CSS in HTML?

Where should I include my JavaScript and CSS code in the HTML page – inline or external file? The typical answer is: Add JavaScript code by the end of the </body> tag and. Add CSS code in-between the <head> tags.

Can you inject JavaScript into HTML?

Inline JavaScriptYou can insert JavaScript directly into an HTML file.

HOW include JavaScript file in index HTML?

To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.


1 Answers

The suggestion by Chris Traveis worked out pretty nice. So the answer to my problem was solved using https://www.npmjs.com/package/postbuild

like image 72
Mackelito Avatar answered Dec 08 '22 05:12

Mackelito