How do entrypoints work?
See original GitHub issueComing from Gulp+Browserify I am evaluating Brunch because I’m not too satisfied with the speed and complexity of Browserify.
Here is what I have: https://github.com/AndreKR/brunch-react-test
│ brunch-config.js
│ package.json
│
├───deploy
│ ...
│
├───node_modules
│ ...
│
├───pages
│ page1.html
│ page2.html
│
└───resources
another.js
page1.js
page2.js
The pageX.js
files require some npm modules and then use them:
var AnotherModule = require('./another.js');
var React = require('react');
var ReactDOM = require('react-dom');
ReactDOM.render(...);
The pages just include and run them (but I could change that to a require):
<script src="../deploy/page1.js"></script>
This is my brunch-config.js:
module.exports = {
files: {
javascripts: {
entryPoints: {
'resources/page1.js': 'page1.js',
'resources/page2.js': 'page2.js'
}
}
},
paths:{
watched: ["resources"],
public: "deploy"
},
modules: {
wrapper: false
}
};
Basically I want to have page-specific bundles that should include the page-specific Javascript code and their dependencies.
My next question would be how to split common requires (React and ReactDOM) and their dependencies into a separate bundle. But I didn’t even get that far because my config is not working.
If I understood correctly, I have to use entryPoints instead of joinTo if I want to work in terms of dependencies and not in terms of files, correct?
Currently I’m getting the error:
Cannot find module 'react' from '/'
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
Yep.
entryPoints
still allow to have things split into several bundles, akin to what joinTo does.It also is possible to have several entry points write common requires into a separate file. For example, this
Will write
resources/page1.js
and its non-npm deps intopublic/page1.js
, same withpage2.js
. Both of their npm deps will be written intovendor.js
.The sample app you have provided actually builds just fine on my machine. Could it be that something’s messed up with your npm cache? Please try removing
node_modules/
and runningnpm i
, and see it it helps.Either way, I think this issue can be closed for now. I’ll ping here in the future when the PRs for this style of splitting will be ready. In the meantime… use a single bundle maybe