D
D
Denis Bukreev2016-11-05 01:48:07
JavaScript
Denis Bukreev, 2016-11-05 01:48:07

How to connect to the library page from node_modules?

So it goes.
Everyone was too lazy to deal with this issue and constantly copied all the code into the created file and merged it with the main app.js, then downloaded it through the browser and stuffed it manually into the libs folder and then connected it - it was inconvenient and tired.
Here I have npm, gulp and my page which consists of index.html and app.js.
app.js is concatenated into gulp from multiple files in a nearby folder.
And so, for example, I download babel-polyfill via npm, it neatly fits into node_modules and .. what's next? How to connect it?
The last time I manually wrote the path in gulp concat from the project root to the desired file in node_modules - node_modules/babel-polyfill/dist/polyfill.min.js- but this is complete nonsense. There must be an easier way. Maybe just write the name of the module and gulp will find it according to its algorithms?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
O
Oleg, 2016-11-05
@ptrvch

Take a look at gulp-inject
Specify in gulpfile the paths to the files you want to include, and they will be included in the location that you specify in the desired .html file

M
mayor-jojo, 2016-11-05
@mayor-jojo

require('babel-polyfill')
Browserify

A
Anton, 2016-11-05
@SPAHI4

rollupjs.org - seems to be the best module loader at the moment
example

import $ from "jquery";
import 'utils/myutil'; // .js на конце не обязателен

$(document)...

And we make a build (I recommend using npm scripts)
rollup src/main.js --output bundle.js

D
Dmitry Belyaev, 2016-11-05
@bingo347

Try webpack
IMHO, the best tool for dealing with modules

B
bezalkogoln1y-coder, 2020-10-12
@bezalkogoln1y-coder

I do through a separate task.
I just collect the entire library of connections into one file.

// Библиотека CSS
function libsCSS() {
   return src([
      'node_modules/bootstrap/dist/css/bootstrap.css',
      'node_modules/@fancyapps/fancybox/dist/jquery.fancybox.css',
   ])
      .pipe(concat('libs.min.css'))
      .pipe(csso())
      .pipe(dest('build/css'));
}

//Библиотека JS
function libsJS() {
   return src([
      'node_modules/jquery/dist/jquery.js',
      'node_modules/@popperjs/core/dist/umd/popper.js',
      'node_modules/bootstrap/dist/js/bootstrap.js',
      'node_modules/lodash/lodash.js',
      'node_modules/@fancyapps/fancybox/dist/jquery.fancybox.js',
   ])
      .pipe(concat('libs.min.js'))
      .pipe(minifyjs())
      .pipe(dest('build/js'));
}

But the better version of the user Oleg .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question