Answer the question
In order to leave comments, you need to log in
How to make a bundle using browserify without including external modules that will be loaded from the CDN?
As you know, by default, when creating a bundle, browserify also includes third-party modules from NPM. But I would like these modules to be loaded from the CDN, and only my own code in the bundle. Tried options for browserify: exclude, external, ignore. But all this led to the fact that third-party modules were not found. Below is the html code:
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title></title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.min.js"></script>
</head>
<body>
<div id="app">
<p style="color: darkred;">JavaScript is not allowed either in the app error.</p>
</div>
<script src="app.js"></script>
</body>
</html>
gulp.task('bundle', ['compile'], () => {
//var b = browserify('build/spa/Main.js', {bundleExternal: false});
var b = browserify('build/spa/Main.js');
b
//.ignore('react')
//.ignore('react-dom')
.bundle()
.pipe(source('app.js'))
.pipe(gulp.dest('dist'));
gulp
.src('src/spa/index.html')
.pipe(gulp.dest('dist'));
});
Answer the question
In order to leave comments, you need to log in
So, my solution to the problem, found after a break for physical education and subsequent re-reading of the README of the browserify-shim package: Install the browserify-shim
module:
Add the following lines to the package.json of the project:
"browserify": {
"transform": ["browserify-shim"]
},
"browserify-shim": {
"react": "global:React",
"react-dom": "global:ReactDOM"
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question