Answer the question
In order to leave comments, you need to log in
How to set a global variable in Browserify?
I use Gulp + Browserify. There is such a task for building JS:
const scriptsServe = () => {
const alias = [
'all-page.js',
'index-page.js'
];
PATH.src.scripts.forEach((entry, index) => {
const bundle = browserify({
entries: entry
});
bundle.transform(babelify);
bundle.bundle()
.pipe(source(alias[index]))
.pipe(gulp.dest(PATH.dest.scripts));
});
};
"browserify-shim": {
"jquery": "global:$"
},
"browserify": {
"transform": [ "browserify-shim" ]
}
import $ from 'jquery';
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question