Skip to content

Commit

Permalink
feat(node-resolve): add native node es modules support (rollup#413)
Browse files Browse the repository at this point in the history
Ref rollup#412

Enable native node es modules via "exports" field in package.json.
Added custom plugin to generate nested package.json with {"type": "module"}
as an alternative to mjs extension usage. This works similar to rollup distribution.
https://unpkg.com/browse/rollup@2.10.9/dist/es/
  • Loading branch information
TrySound authored and LarsDenBakker committed Sep 12, 2020
1 parent 7afa898 commit 2f12f51
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions packages/node-resolve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"author": "Rich Harris <richard.a.harris@gmail.com>",
"homepage": "https://github.com/rollup/plugins/tree/master/packages/node-resolve/#readme",
"bugs": "https://github.com/rollup/plugins/issues",
"main": "dist/index.js",
"main": "./dist/cjs/index.js",
"engines": {
"node": ">= 8.0.0"
},
Expand Down Expand Up @@ -75,6 +75,11 @@
"!**/types.ts"
]
},
"module": "dist/index.es.js",
"exports": {
"require": "./dist/cjs/index.js",
"import": "./dist/es/index.js"
},
"module": "./dist/es/index.js",
"type": "commonjs",
"types": "types/index.d.ts"
}
6 changes: 4 additions & 2 deletions packages/node-resolve/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import babel from 'rollup-plugin-babel';
import json from '@rollup/plugin-json';

import { emitModulePackageFile } from '../../shared/rollup.config';

import pkg from './package.json';

export default {
Expand All @@ -22,7 +24,7 @@ export default {
],
external: Object.keys(pkg.dependencies).concat(['fs', 'path', 'os', 'util']),
output: [
{ file: pkg.main, format: 'cjs' },
{ file: pkg.module, format: 'es' }
{ file: pkg.main, format: 'cjs', exports: 'named' },
{ file: pkg.module, format: 'es', plugins: [emitModulePackageFile()] }
]
};

0 comments on commit 2f12f51

Please sign in to comment.