11

I use webpack for bundling the client side and want to use it for building node/npm library. I saw I can specify the target as node for this. From the doc,

"node" Compile for usage in a node.js-like environment (use require to load chunks)

But the problem is react.js is bundled in the compile output. I want only my source files and any dependencies listed in package.json to be included. I have specified react as peerDependency, like

"peerDependencies": {
    "react": ">=0.13",
    "react-tap-event-plugin": ">=0.1.3"
  },

I also try defining react in externals expecting it may just create the symbol and not include the library itself, but it still includes react in compiled output.

 target: "node",
    externals: [{
        'react' : 'React',
    }]

so, is there a way to use webpack to bundle by server side / node code, but also to specify not to bundle some of the dependencies (which may be defined as peerDependencies or devDependencies)?

1
  • 1
    In you webpack.config.js add target: 'node'. Commented Aug 6, 2016 at 21:13

1 Answer 1

15

James had written a 3 part series on it.

http://jlongster.com/Backend-Apps-with-Webpack--Part-I

following his code, externals were set as

{ 'babel-core': 'commonjs babel-core',
  'babel-loader': 'commonjs babel-loader',
  classnames: 'commonjs classnames',
  react: 'commonjs react',
...
}

which worked great.

Sign up to request clarification or add additional context in comments.

1 Comment

This isn't necessary anymore. As mentioned by @rubens-mariuzzo, a simple "target: 'node'" in your webpack.config.js should do the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.