2021-09-17 15:27:31 +08:00
|
|
|
import path from 'path'
|
2021-10-20 09:42:32 +08:00
|
|
|
import fs from 'fs'
|
2021-08-24 13:36:48 +08:00
|
|
|
import { nodeResolve } from '@rollup/plugin-node-resolve'
|
2021-09-26 01:29:07 +08:00
|
|
|
import { rollup } from 'rollup'
|
2021-08-24 13:36:48 +08:00
|
|
|
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'
|
2021-09-27 15:24:45 +08:00
|
|
|
import { parallel } from 'gulp'
|
2021-10-20 09:42:32 +08:00
|
|
|
import { genEntryTypes } from './entry-types'
|
|
|
|
import { RollupResolveEntryPlugin } from './rollup-plugin-entry'
|
2021-09-26 01:29:07 +08:00
|
|
|
import { epRoot, epOutput } from './utils/paths'
|
2021-10-20 09:42:32 +08:00
|
|
|
import { yellow, green } from './utils/log'
|
|
|
|
import {
|
|
|
|
generateExternal,
|
|
|
|
rollupPathRewriter,
|
|
|
|
writeBundles,
|
|
|
|
} from './utils/rollup'
|
|
|
|
import { buildConfig } from './info'
|
|
|
|
import { run } from './utils/process'
|
2021-10-18 14:45:57 +08:00
|
|
|
import { withTaskName } from './utils/gulp'
|
2021-10-20 09:42:32 +08:00
|
|
|
import type { BuildConfigEntries } from './info'
|
|
|
|
|
|
|
|
import type { RollupOptions, OutputOptions, InputOptions } from 'rollup'
|
|
|
|
|
|
|
|
const getConfig = async (
|
|
|
|
opt: {
|
|
|
|
minify?: boolean
|
|
|
|
sourceMap?: boolean
|
|
|
|
plugins?: InputOptions['plugins']
|
|
|
|
} = {}
|
|
|
|
): Promise<RollupOptions> => ({
|
|
|
|
input: path.resolve(epRoot, 'index.ts'),
|
|
|
|
plugins: [
|
|
|
|
nodeResolve(),
|
|
|
|
vue({
|
|
|
|
target: 'browser',
|
|
|
|
// css: false,
|
|
|
|
exposeFilename: false,
|
|
|
|
}),
|
|
|
|
commonjs(),
|
|
|
|
esbuild({
|
|
|
|
minify: opt.minify,
|
|
|
|
sourceMap: opt.sourceMap,
|
|
|
|
}),
|
|
|
|
replace({
|
|
|
|
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
|
|
}),
|
|
|
|
...(opt.plugins ?? []),
|
|
|
|
],
|
|
|
|
external: await generateExternal({ full: true }),
|
|
|
|
})
|
2021-09-26 01:29:07 +08:00
|
|
|
|
2021-09-27 15:24:45 +08:00
|
|
|
export const buildFull = (minify: boolean) => async () => {
|
2021-10-20 09:42:32 +08:00
|
|
|
const bundle = await rollup(
|
|
|
|
await getConfig({
|
|
|
|
plugins: [RollupResolveEntryPlugin()],
|
|
|
|
minify,
|
|
|
|
sourceMap: minify,
|
|
|
|
})
|
|
|
|
)
|
2021-09-27 15:24:45 +08:00
|
|
|
await writeBundles(bundle, [
|
|
|
|
{
|
|
|
|
format: 'umd',
|
|
|
|
file: path.resolve(epOutput, `dist/index.full${minify ? '.min' : ''}.js`),
|
|
|
|
exports: 'named',
|
|
|
|
name: 'ElementPlus',
|
|
|
|
globals: {
|
|
|
|
vue: 'Vue',
|
|
|
|
},
|
|
|
|
sourcemap: minify,
|
2021-08-25 01:22:03 +08:00
|
|
|
},
|
2021-09-27 15:24:45 +08:00
|
|
|
{
|
|
|
|
format: 'esm',
|
|
|
|
file: path.resolve(
|
|
|
|
epOutput,
|
|
|
|
`dist/index.full${minify ? '.min' : ''}.mjs`
|
|
|
|
),
|
|
|
|
sourcemap: minify,
|
|
|
|
},
|
|
|
|
])
|
2021-09-26 01:29:07 +08:00
|
|
|
}
|
2021-08-24 13:36:48 +08:00
|
|
|
|
2021-10-20 09:42:32 +08:00
|
|
|
export const buildEntry = async () => {
|
|
|
|
const entryFiles = await fs.promises.readdir(epRoot, {
|
|
|
|
withFileTypes: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
const entryPoints = entryFiles
|
|
|
|
.filter((f) => f.isFile())
|
|
|
|
.filter((f) => !['package.json', 'README.md'].includes(f.name))
|
|
|
|
.map((f) => path.resolve(epRoot, f.name))
|
|
|
|
|
|
|
|
const bundle = await rollup({
|
|
|
|
...(await getConfig()),
|
|
|
|
input: entryPoints,
|
|
|
|
external: () => true,
|
|
|
|
})
|
|
|
|
|
|
|
|
yellow('Generating entries')
|
|
|
|
const rewriter = await rollupPathRewriter()
|
|
|
|
writeBundles(
|
|
|
|
bundle,
|
|
|
|
(Object.entries(buildConfig) as BuildConfigEntries).map(
|
|
|
|
([module, config]): OutputOptions => ({
|
|
|
|
format: config.format,
|
|
|
|
dir: config.output.path,
|
|
|
|
exports: config.format === 'cjs' ? 'named' : undefined,
|
|
|
|
paths: rewriter(module),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
|
|
|
green('entries generated')
|
|
|
|
}
|
|
|
|
|
|
|
|
export const copyFullStyle = () =>
|
|
|
|
Promise.all([
|
|
|
|
run(`cp ${epOutput}/theme-chalk/index.css ${epOutput}/dist/index.css`),
|
|
|
|
run(`cp -R ${epOutput}/theme-chalk/fonts ${epOutput}/dist/fonts`),
|
|
|
|
])
|
|
|
|
|
2021-09-27 15:24:45 +08:00
|
|
|
export const buildFullBundle = parallel(
|
|
|
|
withTaskName('buildFullMinified', buildFull(true)),
|
2021-10-20 09:42:32 +08:00
|
|
|
withTaskName('buildFull', buildFull(false)),
|
|
|
|
buildEntry,
|
|
|
|
genEntryTypes
|
2021-09-26 01:29:07 +08:00
|
|
|
)
|