Skip to content

Commit

Permalink
feat(node-resolve): add native node es modules support (#413)
Browse files Browse the repository at this point in the history
Ref #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 Jun 7, 2020
1 parent 80d0da9 commit 39eb61c
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()] }
]
};

1 comment on commit 39eb61c

@vladshcherbin

This comment was marked as spam.

Please sign in to comment.