mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-11-30 18:27:40 +08:00
4e99d0b5ba
* build!: simplify build & support native esm import * build: refactor build * refactor: reorganize files * refactor: refactor build * build: improve perf * fix: scripts * build: add rollup-plugin-filesize * chore: scripts ignore no-console * build: disable tree-shaking * build: improve code * build: add sourcemap * build: add banner * refactor: remove annotation * build!: improve esm exports (#3871) * build: improve esm import * refactor: change mjs for esm version * chore: improve exports map * fix: add sideEffects * refactor: improve alias * build: upgrade dependencies
70 lines
1.9 KiB
TypeScript
70 lines
1.9 KiB
TypeScript
import path from 'path'
|
|
import { nodeResolve } from '@rollup/plugin-node-resolve'
|
|
import { rollup } from 'rollup'
|
|
import commonjs from '@rollup/plugin-commonjs'
|
|
import vue from 'rollup-plugin-vue'
|
|
import esbuild from 'rollup-plugin-esbuild'
|
|
import replace from '@rollup/plugin-replace'
|
|
import filesize from 'rollup-plugin-filesize'
|
|
import { parallel } from 'gulp'
|
|
import { version } from '../packages/element-plus/version'
|
|
import { ElementPlusAlias } from './plugins/element-plus-alias'
|
|
import { epRoot, epOutput } from './utils/paths'
|
|
import { generateExternal, writeBundles } from './utils/rollup'
|
|
|
|
import { withTaskName } from './utils/gulp'
|
|
|
|
export const buildFull = (minify: boolean) => async () => {
|
|
const bundle = await rollup({
|
|
input: path.resolve(epRoot, 'index.ts'),
|
|
plugins: [
|
|
await ElementPlusAlias(),
|
|
nodeResolve({
|
|
extensions: ['.mjs', '.js', '.json', '.ts'],
|
|
}),
|
|
vue({
|
|
target: 'browser',
|
|
exposeFilename: false,
|
|
}),
|
|
commonjs(),
|
|
esbuild({ minify, sourceMap: minify }),
|
|
replace({
|
|
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
|
|
// options
|
|
preventAssignment: true,
|
|
}),
|
|
filesize(),
|
|
],
|
|
external: await generateExternal({ full: true }),
|
|
})
|
|
const banner = `/*! Element Plus v${version} */\n`
|
|
await writeBundles(bundle, [
|
|
{
|
|
format: 'umd',
|
|
file: path.resolve(epOutput, `dist/index.full${minify ? '.min' : ''}.js`),
|
|
exports: 'named',
|
|
name: 'ElementPlus',
|
|
globals: {
|
|
vue: 'Vue',
|
|
},
|
|
sourcemap: minify,
|
|
banner,
|
|
},
|
|
{
|
|
format: 'esm',
|
|
file: path.resolve(
|
|
epOutput,
|
|
`dist/index.full${minify ? '.min' : ''}.mjs`
|
|
),
|
|
sourcemap: minify,
|
|
banner,
|
|
},
|
|
])
|
|
}
|
|
|
|
export const buildFullBundle = parallel(
|
|
withTaskName('buildFullMinified', buildFull(true)),
|
|
withTaskName('buildFull', buildFull(false))
|
|
)
|