Reputation: 58742
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
)?
Upvotes: 11
Views: 11442
Reputation: 58742
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.
Upvotes: 15