Answer the question
In order to leave comments, you need to log in
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
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
rollupjs.org - seems to be the best module loader at the moment
example
import $ from "jquery";
import 'utils/myutil'; // .js на конце не обязателен
$(document)...
rollup src/main.js --output bundle.js
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'));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question