Skip to content

Commit

Permalink
Merge pull request #3 from stauren/feat/add-cjs-export
Browse files Browse the repository at this point in the history
add cjs export for issue #2
  • Loading branch information
stauren committed Nov 16, 2023
2 parents 1f1746c + 2706e0e commit ffa9da5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# [1.0.2](https://github.com/stauren/vite-plugin-deadfile/tree/v1.0.2) (2023-11-16)

- support cjx export https://github.com/stauren/vite-plugin-deadfile/issues/2

# [1.0.1](https://github.com/stauren/vite-plugin-deadfile/tree/v1.0.1) (2023-11-14)

- fix a esm related bug
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ export default defineConfig({
});
```

## Output format

```text
All source files: 123
Used source files: 120
Unused source files: 3
./path/to/unused/file-a
./path/to/unused/file-b
./path/to/unused/file-c
```

## Options

### include
Expand Down Expand Up @@ -65,17 +76,6 @@ export default defineConfig({
});
```

## Output format

```text
All source files: 123
Used source files: 120
Unused source files: 3
./path/to/unused/file-a
./path/to/unused/file-b
./path/to/unused/file-c
```

## Caveats

### Pure Type Reference can NOT be traced
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-deadfile",
"version": "1.0.1",
"version": "1.0.2",
"license": "MIT",
"author": "stauren@qq.com",
"type": "module",
Expand All @@ -11,10 +11,11 @@
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
"require": "./dist/index.cjs",
"import": "./dist/index.js"
},
"scripts": {
"build": "rollup -c rollup.config.js"
"build": "rollup -c rollup.config.js && node ./scripts/generate-esm-wrapper.js"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import pkg from './package.json' assert { type: 'json' };
export default {
input: 'src/index.ts',
output: [{
file: pkg.exports['.'],
file: pkg.exports.require,
sourcemap: false,
format: 'esm',
format: 'cjs',
}],
external: [
'node:fs',
Expand Down
12 changes: 12 additions & 0 deletions scripts/generate-esm-wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { promises as fs } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
import pkg from '../package.json' assert { type: 'json' };

const base = dirname(fileURLToPath(import.meta.url));
const esmFile = resolve(base, '..', pkg.exports.import);
const content = `import vitePluginDeadFile from './index.cjs';
export default vitePluginDeadFile;
`;

fs.writeFile(esmFile, content);

0 comments on commit ffa9da5

Please sign in to comment.