2021-10-25 17:07:48 +08:00
|
|
|
import { rollup } from 'rollup'
|
2022-01-22 10:05:03 +08:00
|
|
|
import vue from '@vitejs/plugin-vue'
|
2022-02-11 12:10:56 +08:00
|
|
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
2022-02-11 11:39:49 +08:00
|
|
|
import DefineOptions from 'unplugin-vue-define-options/vite'
|
2021-10-25 17:07:48 +08:00
|
|
|
import css from 'rollup-plugin-css-only'
|
|
|
|
import { nodeResolve } from '@rollup/plugin-node-resolve'
|
|
|
|
import commonjs from '@rollup/plugin-commonjs'
|
|
|
|
import esbuild from 'rollup-plugin-esbuild'
|
|
|
|
import filesize from 'rollup-plugin-filesize'
|
|
|
|
import glob from 'fast-glob'
|
|
|
|
import { epRoot, pkgRoot } from './utils/paths'
|
|
|
|
import { ElementPlusAlias } from './plugins/element-plus-alias'
|
|
|
|
import { generateExternal, writeBundles } from './utils/rollup'
|
|
|
|
import { excludeFiles } from './utils/pkg'
|
|
|
|
import { reporter } from './plugins/size-reporter'
|
2022-01-17 11:19:11 +08:00
|
|
|
import { buildConfigEntries, target } from './build-info'
|
2021-10-25 17:07:48 +08:00
|
|
|
import type { OutputOptions } from 'rollup'
|
|
|
|
|
|
|
|
export const buildModules = async () => {
|
|
|
|
const input = excludeFiles(
|
|
|
|
await glob('**/*.{js,ts,vue}', {
|
|
|
|
cwd: pkgRoot,
|
|
|
|
absolute: true,
|
|
|
|
onlyFiles: true,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
const bundle = await rollup({
|
|
|
|
input,
|
|
|
|
plugins: [
|
2022-01-17 11:19:11 +08:00
|
|
|
ElementPlusAlias(),
|
2021-10-25 17:07:48 +08:00
|
|
|
css(),
|
2022-02-11 11:39:49 +08:00
|
|
|
DefineOptions(),
|
2022-01-22 10:05:03 +08:00
|
|
|
vue({
|
|
|
|
isProduction: false,
|
|
|
|
}),
|
2022-02-11 12:10:56 +08:00
|
|
|
vueJsx(),
|
2021-10-25 17:07:48 +08:00
|
|
|
nodeResolve({
|
|
|
|
extensions: ['.mjs', '.js', '.json', '.ts'],
|
|
|
|
}),
|
|
|
|
commonjs(),
|
|
|
|
esbuild({
|
|
|
|
sourceMap: true,
|
2022-01-17 11:19:11 +08:00
|
|
|
target,
|
2022-01-24 23:31:08 +08:00
|
|
|
loaders: {
|
|
|
|
'.vue': 'ts',
|
|
|
|
},
|
2021-10-25 17:07:48 +08:00
|
|
|
}),
|
|
|
|
filesize({ reporter }),
|
|
|
|
],
|
|
|
|
external: await generateExternal({ full: false }),
|
2022-01-22 19:32:03 +08:00
|
|
|
treeshake: false,
|
2021-10-25 17:07:48 +08:00
|
|
|
})
|
|
|
|
await writeBundles(
|
|
|
|
bundle,
|
|
|
|
buildConfigEntries.map(([module, config]): OutputOptions => {
|
|
|
|
return {
|
|
|
|
format: config.format,
|
|
|
|
dir: config.output.path,
|
|
|
|
exports: module === 'cjs' ? 'named' : undefined,
|
|
|
|
preserveModules: true,
|
|
|
|
preserveModulesRoot: epRoot,
|
|
|
|
sourcemap: true,
|
|
|
|
entryFileNames: `[name].${config.ext}`,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|