javascript - How to assembly js libs in an angular application -


i'm starting first angular application (for information, angular2). starting learn tools nodejs, gulp, etc...

i have nodejs server, serves server stuff , front stuff.

for front stuff, have html, css, resources, , js files. working angular, have required dependencies in node_modules.

i'm ok typescripts management gulp. have managed have app js files concatenated in "build" target folder.

now, want copy there libs/dependencies, index.html have 2 script include : myapp.js , libs.js (minified angular , possibly other libs).

i cannot find way that. got result webpack, minifies app in libs.js file, , want app separate can debug in non minified js dev mode.

is there way extract node_modules required libs app, minify them , concat them in compact libs.js ?

when parse node_modules, huge repository (mainly due server dependencies stuff gulp, mocha, ... nothing useful frontend), , i'm pretty sure taking node_modules/**/*.js , concat not idea!

thank response.

you can use browserify. allows use require() function in node.js. there gulp plugin.

so example if want use lodash, first run npm install --save lodash, in javascript have:

var _ = require('lodash'); // here can use lodash normal 

the files can both compiled node server or precompiled gulp.

once compiled, files bundled every dependency declared using require()

edit

to answer comment, if want export separate file including libraries, can this

libs.js
window._ = require('lodash'); window.$ = require('jquery'); // other library 
app.js
// here can use libraries normal console.log(_); console.log($); 
index.html
<script type="text/javascript" src="js/libs.js"></script> <script type="text/javascript" src="js/app.js"></script> 

but prefer have 1 file bundled.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -