build(util): umd版本将lodash-es打进去

This commit is contained in:
roymondchen 2024-01-03 16:32:44 +08:00
parent 3c167f3b54
commit 5a5288c9da
2 changed files with 9 additions and 4 deletions

View File

@ -18,7 +18,7 @@
},
"license": "Apache-2.0",
"scripts": {
"build": "npm run build:type && vite build",
"build": "rimraf ./dist && npm run build:type && vite build --mode=es && vite build --mode=umd",
"build:type": "npm run clear:type && tsc --declaration --emitDeclarationOnly --project tsconfig.build.json",
"clear:type": "rimraf ./types"
},

View File

@ -16,30 +16,35 @@
* limitations under the License.
*/
import { defineConfig } from 'vite';
import { defineConfig, type LibraryFormats } from 'vite';
import pkg from './package.json';
const deps = Object.keys(pkg.dependencies);
export default defineConfig({
export default defineConfig(({ mode }) => ({
build: {
cssCodeSplit: false,
sourcemap: true,
minify: false,
target: 'esnext',
emptyOutDir: false,
lib: {
entry: 'src/index.ts',
name: 'TMagicUtils',
formats: ['es', 'umd', 'cjs'].includes(mode) ? [mode as LibraryFormats] : ['es', 'umd'],
fileName: 'tmagic-utils',
},
rollupOptions: {
// 确保外部化处理那些你不想打包进库的依赖
external(id: string) {
if (mode === 'umd' && id === 'lodash-es') {
return false;
}
return deps.some((k) => new RegExp(`^${k}`).test(id));
},
},
},
});
}));