代码拉取完成,页面将自动刷新
import { build, context } from 'esbuild'
import vue from 'esbuild-plugin-vue'
import progress from 'esbuild-plugin-progress'
import { esbuildPluginFileSize } from 'esbuild-plugin-filesize'
import esbuildStylePlugin from 'esbuild-style-plugin'
import autoprefixer from 'autoprefixer'
import postcssPresetEnv from 'postcss-preset-env'
import postcssImport from 'postcss-import'
import postcssMinify from 'postcss-minify'
import esbuildPluginBowserSync from 'esbuild-plugin-browser-sync'
import esbuildHtmlPlugin from '@fallen_leaves/esbuild-plugin-html'
import components from './components.js'
// 包名
const libraryName = 'fa-ui'
const globalName = 'FaUI'
// 打包组件库
async function buildLibrary () {
await build({
entryPoints: ['packages/index.ts'],
outfile: `lib/${libraryName}.js`,
bundle: true,
format: 'esm',
tsconfig: 'tsconfig.json',
treeShaking: true,
external: ['vue'],
assetNames: '[dir]/[name]-[hash]',
loader: {
'.eot': 'file',
'.svg': 'file',
'.ttf': 'file',
'.woff': 'file'
},
define: {
'__VUE_OPTIONS_API__': 'true',
'__VUE_PROD_DEVTOOLS__': 'false'
},
plugins: [
esbuildStylePlugin({
postcss: {
plugins: [
autoprefixer({
overrideBrowserslist: ['last 10 version']
}),
postcssImport(),
postcssPresetEnv(),
postcssMinify()
]
}
}),
vue(),
progress(),
esbuildPluginFileSize()
]
})
await build({
entryPoints: ['packages/index.ts'],
outfile: `lib/${libraryName}.min.js`,
bundle: true,
format: 'iife',
tsconfig: 'tsconfig.json',
globalName,
treeShaking: true,
minify: true,
external: ['vue'],
define: {
'__VUE_OPTIONS_API__': 'true',
'__VUE_PROD_DEVTOOLS__': 'false'
},
loader: {
'.eot': 'dataurl',
'.svg': 'dataurl',
'.ttf': 'dataurl',
'.woff': 'dataurl'
},
plugins: [
esbuildStylePlugin({
postcss: {
plugins: [
autoprefixer({
overrideBrowserslist: ['last 10 version']
}),
postcssImport(),
postcssPresetEnv(),
postcssMinify()
]
}
}),
vue(),
progress(),
esbuildPluginFileSize()
]
})
await build({
entryPoints: Object.values(components),
outdir: 'lib',
bundle: true,
format: 'esm',
tsconfig: 'tsconfig.json',
treeShaking: true,
external: ['vue'],
assetNames: '[dir]/[name]',
loader: {
'.eot': 'dataurl',
'.svg': 'dataurl',
'.ttf': 'dataurl',
'.woff': 'dataurl'
},
mainFields: ['module'],
define: {
'__VUE_OPTIONS_API__': 'true',
'__VUE_PROD_DEVTOOLS__': 'false'
},
plugins: [
esbuildStylePlugin({
postcss: {
plugins: [
autoprefixer({
overrideBrowserslist: ['last 10 version']
}),
postcssImport(),
postcssPresetEnv(),
postcssMinify()
]
}
}),
vue(),
progress()
]
})
}
// 打包预览页面
async function buildExamples () {
const ctx = await context({
entryPoints: ['examples/main.ts'],
outdir: 'dist/static',
bundle: true,
tsconfig: 'tsconfig.json',
format: 'iife',
sourcemap: true,
loader: {
'.eot': 'file',
'.svg': 'file',
'.ttf': 'file',
'.woff': 'file'
},
define: {
'__VUE_OPTIONS_API__': 'true',
'__VUE_PROD_DEVTOOLS__': 'false'
},
plugins: [
esbuildStylePlugin({
postcss: {
plugins: [
autoprefixer({
overrideBrowserslist: ['last 10 version']
}),
postcssImport(),
postcssPresetEnv(),
postcssMinify()
]
}
}),
vue(),
progress(),
esbuildHtmlPlugin({
template: 'examples/index.html',
filename: 'dist/index.html',
minify: true
}),
esbuildPluginBowserSync({
server: 'dist'
})
]
})
await ctx.watch()
}
// 启动函数
(async (isServe) => {
if (isServe) {
buildExamples()
} else {
buildLibrary()
}
})(process.argv.includes('serve'))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。