diff --git a/.gitignore b/.gitignore index 6d44c32c..39d9fcdd 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,4 @@ node_modules .cache .parcel-cache demo/.vitepress/dist -yarn.lock -package-lock.json .DS_Store diff --git a/package.json b/package.json index 45490647..805f0b47 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,30 @@ { "name": "jessibuca", "version": "1.0.0", + "main": "dist/jessibuca.js", + "module": "dist/jessibuca.esm.js", + "unpkg": "dist/jessibuca.js", + "jsdelivr": "dist/jessibuca.js", + "types": "dist/jessibuca.d.ts", + "files": [ + "dist", + "package.json", + "LICENSE", + "README.md", + "README.en.md" + ], + "exports": { + ".": { + "import": { + "types": "./dist/jessibuca.d.ts", + "default": "./dist/jessibuca.esm.js" + }, + "require": { + "types": "./dist/jessibuca.d.ts", + "default": "./dist/jessibuca.js" + } + } + }, "scripts": { "build": "npx cross-env NODE_ENV=production rollup -c", "build:wasm": "python wasm/make.py --wasm && npm run build && npm run build:demo", @@ -41,7 +65,6 @@ "rollup-plugin-replace": "^2.2.0", "rollup-plugin-string": "^3.0.0", "rollup-plugin-terser": "^7.0.2", - "rollup-plugin-worker-inline": "^1.0.6", "rollup-plugin-copy": "^3.4.0", "servor": "^4.0.2" }, diff --git a/rollup.config.js b/rollup.config.js index 5ee6fd39..832105ec 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -9,13 +9,13 @@ import json from '@rollup/plugin-json'; // 解析json格式 import copy from 'rollup-plugin-copy'; // 直接复制文件和文件夹。 import {terser} from 'rollup-plugin-terser'; // 压缩 import base64 from 'postcss-base64'; // 图片变成base64 +import packageJson from './package.json'; const isProd = process.env.NODE_ENV === 'production'; const baseConfig = { output: { - format: 'umd', sourcemap: !isProd, }, plugins: [ @@ -72,10 +72,19 @@ const baseConfig = { export default [ { input: 'src/jessibuca.js', - output: { - name: 'jessibuca', - file: isProd ? 'dist/jessibuca.js' : 'demo/public/jessibuca.js', - }, + output: [ + { + name: 'jessibuca', + file: isProd ? packageJson.main : 'demo/public/jessibuca.js', + format: 'umd', + ...baseConfig.output + }, + { + file: isProd ? packageJson.module : 'demo/public/jessibuca.js', + format: 'esm', + ...baseConfig.output + } + ], plugins: [ postcss({ plugins: [ @@ -99,16 +108,14 @@ export default [ output: { name: 'decoder', file: isProd ? 'dist/decoder.js' : 'demo/public/decoder.js', + ...baseConfig.output }, plugins: [], } ].map(config => { return { input: config.input, - output: { - ...baseConfig.output, - ...config.output, - }, + output: config.output, plugins: [...baseConfig.plugins, ...config.plugins], }; });