diff --git a/CHANGELOG.md b/CHANGELOG.md index 86be9ab..7517a03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 2460cd3..df86d19 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/package.json b/package.json index 7a58966..280b902 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vite-plugin-deadfile", - "version": "1.0.1", + "version": "1.0.2", "license": "MIT", "author": "stauren@qq.com", "type": "module", @@ -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", diff --git a/rollup.config.js b/rollup.config.js index cf4ffa6..8db3406 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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', diff --git a/scripts/generate-esm-wrapper.js b/scripts/generate-esm-wrapper.js new file mode 100644 index 0000000..0f13f3b --- /dev/null +++ b/scripts/generate-esm-wrapper.js @@ -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);