element-plus/build/full-bundle.ts

74 lines
1.9 KiB
TypeScript
Raw Normal View History

import path from 'path'
import { nodeResolve } from '@rollup/plugin-node-resolve'
2021-09-26 01:29:07 +08:00
import { rollup } from 'rollup'
import commonjs from '@rollup/plugin-commonjs'
import vue from 'rollup-plugin-vue'
import esbuild from 'rollup-plugin-esbuild'
2021-09-26 01:29:07 +08:00
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'
2021-09-26 01:29:07 +08:00
import { epRoot, epOutput } from './utils/paths'
import { generateExternal, writeBundles } from './utils/rollup'
import { withTaskName } from './utils/gulp'
2021-09-26 01:29:07 +08:00
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,
target: 'es2018',
}),
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,
},
])
2021-09-26 01:29:07 +08:00
}
export const buildFullBundle = parallel(
withTaskName('buildFullMinified', buildFull(true)),
withTaskName('buildFull', buildFull(false))
2021-09-26 01:29:07 +08:00
)