question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do entrypoints work?

See original GitHub issue

Coming 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:closed
  • Created 7 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
goshacmdcommented, May 7, 2016

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?

Yep.

My next question would be how to split common requires (React and ReactDOM) and their dependencies into a separate bundle

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

      entryPoints: {
        'resources/page1.js': {
          'page1.js': /^resources/,
          'vendor.js': /^(?!resources)/
        },
        'resources/page2.js': {
          'page2.js': /^resources/,
          'vendor.js': /^(?!resources)/
        }
      }

Will write resources/page1.js and its non-npm deps into public/page1.js, same with page2.js. Both of their npm deps will be written into vendor.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 running npm i, and see it it helps.


  brunch:generate Concatenating [resources/another.js, resources/page1.js] => deploy/page1.js +3ms
  brunch:generate Concatenating [node_modules/fbjs/lib/EventListener.js, node_modules/fbjs/lib/ExecutionEnvironment.js, node_modules/fbjs/lib/camelize.js, node_modules/fbjs/lib/camelizeStyleName.js, node_modules/fbjs/lib/containsNode.js, node_modules/fbjs/lib/createArrayFromMixed.js, node_modules/fbjs/lib/createNodesFromMarkup.js, node_modules/fbjs/lib/emptyFunction.js, node_modules/fbjs/lib/emptyObject.js, node_modules/fbjs/lib/focusNode.js, node_modules/fbjs/lib/getActiveElement.js, node_modules/fbjs/lib/getMarkupWrap.js, node_modules/fbjs/lib/getUnboundedScrollPosition.js, node_modules/fbjs/lib/hyphenate.js, node_modules/fbjs/lib/hyphenateStyleName.js, node_modules/fbjs/lib/invariant.js, node_modules/fbjs/lib/isNode.js, node_modules/fbjs/lib/isTextNode.js, node_modules/fbjs/lib/keyMirror.js, node_modules/fbjs/lib/keyOf.js, node_modules/fbjs/lib/mapObject.js, node_modules/fbjs/lib/memoizeStringOnly.js, node_modules/fbjs/lib/performance.js, node_modules/fbjs/lib/performanceNow.js, node_modules/fbjs/lib/shallowEqual.js, node_modules/fbjs/lib/warning.js, node_modules/object-assign/index.js, node_modules/process/browser.js, node_modules/react-dom/index.js, node_modules/react/lib/AutoFocusUtils.js, node_modules/react/lib/BeforeInputEventPlugin.js, node_modules/react/lib/CSSProperty.js, node_modules/react/lib/CSSPropertyOperations.js, node_modules/react/lib/CallbackQueue.js, node_modules/react/lib/ChangeEventPlugin.js, node_modules/react/lib/DOMChildrenOperations.js, node_modules/react/lib/DOMLazyTree.js, node_modules/react/lib/DOMNamespaces.js, node_modules/react/lib/DOMProperty.js, node_modules/react/lib/DOMPropertyOperations.js, node_modules/react/lib/Danger.js, node_modules/react/lib/DefaultEventPluginOrder.js, node_modules/react/lib/DisabledInputUtils.js, node_modules/react/lib/EnterLeaveEventPlugin.js, node_modules/react/lib/EventConstants.js, node_modules/react/lib/EventPluginHub.js, node_modules/react/lib/EventPluginRegistry.js, node_modules/react/lib/EventPluginUtils.js, node_modules/react/lib/EventPropagators.js, node_modules/react/lib/FallbackCompositionState.js, node_modules/react/lib/HTMLDOMPropertyConfig.js, node_modules/react/lib/KeyEscapeUtils.js, node_modules/react/lib/LinkedValueUtils.js, node_modules/react/lib/PooledClass.js, node_modules/react/lib/React.js, node_modules/react/lib/ReactBrowserEventEmitter.js, node_modules/react/lib/ReactChildReconciler.js, node_modules/react/lib/ReactChildren.js, node_modules/react/lib/ReactClass.js, node_modules/react/lib/ReactComponent.js, node_modules/react/lib/ReactComponentBrowserEnvironment.js, node_modules/react/lib/ReactComponentEnvironment.js, node_modules/react/lib/ReactCompositeComponent.js, node_modules/react/lib/ReactCurrentOwner.js, node_modules/react/lib/ReactDOM.js, node_modules/react/lib/ReactDOMButton.js, node_modules/react/lib/ReactDOMComponent.js, node_modules/react/lib/ReactDOMComponentFlags.js, node_modules/react/lib/ReactDOMComponentTree.js, node_modules/react/lib/ReactDOMContainerInfo.js, node_modules/react/lib/ReactDOMDebugTool.js, node_modules/react/lib/ReactDOMEmptyComponent.js, node_modules/react/lib/ReactDOMFactories.js, node_modules/react/lib/ReactDOMFeatureFlags.js, node_modules/react/lib/ReactDOMIDOperations.js, node_modules/react/lib/ReactDOMInput.js, node_modules/react/lib/ReactDOMInstrumentation.js, node_modules/react/lib/ReactDOMOption.js, node_modules/react/lib/ReactDOMSelect.js, node_modules/react/lib/ReactDOMSelection.js, node_modules/react/lib/ReactDOMTextComponent.js, node_modules/react/lib/ReactDOMTextarea.js, node_modules/react/lib/ReactDOMTreeTraversal.js, node_modules/react/lib/ReactDOMUnknownPropertyDevtool.js, node_modules/react/lib/ReactDebugTool.js, node_modules/react/lib/ReactDefaultBatchingStrategy.js, node_modules/react/lib/ReactDefaultInjection.js, node_modules/react/lib/ReactDefaultPerf.js, node_modules/react/lib/ReactDefaultPerfAnalysis.js, node_modules/react/lib/ReactElement.js, node_modules/react/lib/ReactElementValidator.js, node_modules/react/lib/ReactEmptyComponent.js, node_modules/react/lib/ReactErrorUtils.js, node_modules/react/lib/ReactEventEmitterMixin.js, node_modules/react/lib/ReactEventListener.js, node_modules/react/lib/ReactFeatureFlags.js, node_modules/react/lib/ReactInjection.js, node_modules/react/lib/ReactInputSelection.js, node_modules/react/lib/ReactInstanceMap.js, node_modules/react/lib/ReactInstrumentation.js, node_modules/react/lib/ReactInvalidSetStateWarningDevTool.js, node_modules/react/lib/ReactMarkupChecksum.js, node_modules/react/lib/ReactMount.js, node_modules/react/lib/ReactMultiChild.js, node_modules/react/lib/ReactMultiChildUpdateTypes.js, node_modules/react/lib/ReactNativeComponent.js, node_modules/react/lib/ReactNodeTypes.js, node_modules/react/lib/ReactNoopUpdateQueue.js, node_modules/react/lib/ReactOwner.js, node_modules/react/lib/ReactPerf.js, node_modules/react/lib/ReactPropTypeLocationNames.js, node_modules/react/lib/ReactPropTypeLocations.js, node_modules/react/lib/ReactPropTypes.js, node_modules/react/lib/ReactReconcileTransaction.js, node_modules/react/lib/ReactReconciler.js, node_modules/react/lib/ReactRef.js, node_modules/react/lib/ReactUpdateQueue.js, node_modules/react/lib/ReactUpdates.js, node_modules/react/lib/ReactVersion.js, node_modules/react/lib/SVGDOMPropertyConfig.js, node_modules/react/lib/SelectEventPlugin.js, node_modules/react/lib/SimpleEventPlugin.js, node_modules/react/lib/SyntheticAnimationEvent.js, node_modules/react/lib/SyntheticClipboardEvent.js, node_modules/react/lib/SyntheticCompositionEvent.js, node_modules/react/lib/SyntheticDragEvent.js, node_modules/react/lib/SyntheticEvent.js, node_modules/react/lib/SyntheticFocusEvent.js, node_modules/react/lib/SyntheticInputEvent.js, node_modules/react/lib/SyntheticKeyboardEvent.js, node_modules/react/lib/SyntheticMouseEvent.js, node_modules/react/lib/SyntheticTouchEvent.js, node_modules/react/lib/SyntheticTransitionEvent.js, node_modules/react/lib/SyntheticUIEvent.js, node_modules/react/lib/SyntheticWheelEvent.js, node_modules/react/lib/Transaction.js, node_modules/react/lib/ViewportMetrics.js, node_modules/react/lib/accumulateInto.js, node_modules/react/lib/adler32.js, node_modules/react/lib/canDefineProperty.js, node_modules/react/lib/createMicrosoftUnsafeLocalFunction.js, node_modules/react/lib/dangerousStyleValue.js, node_modules/react/lib/escapeTextContentForBrowser.js, node_modules/react/lib/findDOMNode.js, node_modules/react/lib/flattenChildren.js, node_modules/react/lib/forEachAccumulated.js, node_modules/react/lib/getEventCharCode.js, node_modules/react/lib/getEventKey.js, node_modules/react/lib/getEventModifierState.js, node_modules/react/lib/getEventTarget.js, node_modules/react/lib/getIteratorFn.js, node_modules/react/lib/getNativeComponentFromComposite.js, node_modules/react/lib/getNodeForCharacterOffset.js, node_modules/react/lib/getTextContentAccessor.js, node_modules/react/lib/getVendorPrefixedEventName.js, node_modules/react/lib/instantiateReactComponent.js, node_modules/react/lib/isEventSupported.js, node_modules/react/lib/isTextInputElement.js, node_modules/react/lib/onlyChild.js, node_modules/react/lib/quoteAttributeValueForBrowser.js, node_modules/react/lib/renderSubtreeIntoContainer.js, node_modules/react/lib/setInnerHTML.js, node_modules/react/lib/setTextContent.js, node_modules/react/lib/shouldUpdateReactComponent.js, node_modules/react/lib/traverseAllChildren.js, node_modules/react/lib/validateDOMNesting.js, node_modules/react/react.js] => deploy/vendor.js +54ms
  brunch:generate Concatenating [resources/page2.js] => deploy/page2.js +120ms
  brunch:generate Writing deploy/page1.js +2ms
  brunch:generate Writing deploy/vendor.js +0ms
  brunch:generate Writing deploy/page2.js +1ms
  brunch:generate Writing deploy/page1.js.map +16ms
  brunch:generate Writing deploy/vendor.js.map +30ms
  brunch:generate Writing deploy/page2.js.map +0ms
07 May 13:05:34 - info: compiled 169 files into 3 files in 4.8 sec
0reactions
goshacmdcommented, May 10, 2016

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding Docker's CMD and ENTRYPOINT Instructions
This is where the ENTRYPOINT instruction shines. The ENTRYPOINT instruction works very similarly to CMD in that it is used to specify the ......
Read more >
How ENTRYPOINT Works in Docker? - eduCBA
Docker entrypoint is a Dockerfile directive or instruction that is used to specify the executable which should run when a container is started...
Read more >
What is the difference between CMD and ENTRYPOINT in a ...
The ENTRYPOINT specifies a command that will always be executed when the container starts. The CMD specifies arguments that will be fed to...
Read more >
Docker - CMD vs ENTRYPOINT - Atatus
It is used to set executables that will run only when the container is initiated. ENTRYPOINT commands cannot be overridden or ignored even...
Read more >
Understand CMD and ENTRYPOINT Differences in Docker
ENTRYPOINT is the other instruction used to configure how the container will run. Just like with CMD, you need to specify a command...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found