Skip to content

Commit

Permalink
Port doc changes from #4572 and #4583 to 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
berniegp committed Jul 29, 2022
1 parent d196046 commit 85a80d8
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions docs/01-command-line-reference.md
Expand Up @@ -303,41 +303,31 @@ It can be useful to import your package file to e.g. mark your dependencies as "
import pkg from './package.json' assert { type: 'json' };

export default {
input: 'src/main.js',
external: Object.keys(pkg.dependencies),
output: {
format: 'es',
dir: 'dist'
}
// Mark package dependencies as "external". Rest of configuration omitted.
external: Object.keys(pkg.dependencies)
};
```
- For older Node versions, you can use "createRequire"
- For older Node versions, you can use `createRequire`
```js
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const pkg = require('./package.json');

export default {
input: 'src/main.js',
external: Object.keys(pkg.dependencies),
output: {
format: 'es',
dir: 'dist'
}
};
// ...
```
- Or just directly read and parse the file from disk
```js
// rollup.config.mjs
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';

const pkgFileName = fileURLToPath(new URL('./package.json', import.meta.url));
const pkg = JSON.parse(readFileSync(pkgFileName));
// Use import.meta.url to make the path relative to the current source file instead of process.cwd()
// For more info: https://nodejs.org/docs/latest-v16.x/api/esm.html#importmetaurl
const packageJson = JSON.parse(readFileSync(new URL('./package.json', import.meta.url)));

// ...
```
Expand Down

0 comments on commit 85a80d8

Please sign in to comment.