rollup / rollup-plugin-node-resolve

This module has moved and is now available at @rollup/plugin-node-resolve / https://github.com/rollup/plugins/blob/master/packages/node-resolve
MIT License
469 stars 96 forks source link

`external` is ignored when using `rollup-plugin-node-resolve` #210

Closed kamleshchandnani closed 5 years ago

kamleshchandnani commented 5 years ago

I was cleaning up my rollup builds today and I came across my builds. When I was looking deep into it I saw packages which are marked as external are also included by this plugin in my output bundle. So in my config I'm doing something like this external: Object.keys(packageJson.peerDependencies) but seems like node-resolve is not considering them. So looking at the docs I came across only option so to try that out this what I added to my config

nodeResolve({
 only: Object.keys(packageJson.dependencies),
}),

Now after this my externals are not being bundled but rollup throws warning which treats transitive dependencies of these dependencies as external. Isn't this weird?

Here's my rollup.config.js

const serverConfig = fs.readdirSync('src')
  .filter((service) => !ignoreFiles.includes(service))
  .map((service) => ({
    input: `src/${service}/index.js`,
    external: Object.keys(packageJson.peerDependencies),
    plugins: [
      babel({
        exclude: 'node_modules/**',
        runtimeHelpers: true,
        externalHelpers: true,
      }),
      nodeResolve({
        only: Object.keys(packageJson.dependencies),
      }),
      commonjs(),
      json(),
    ],
    output: {
      file: `server/${service}.js`,
      format: 'cjs',
      exports: 'named',
    },
  }));
kamleshchandnani commented 5 years ago

cc @TrySound @lukastaegert

kamleshchandnani commented 5 years ago

Closing this. Since it's not really a bug