1 Star 10 Fork 3

we_coder/vue3-component-library

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
esbuild.config.js 4.25 KB
一键复制 编辑 原始数据 按行查看 历史
we_coder 提交于 2023-02-24 15:27 . !4更新预览打包
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'))
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/we_coder/vue3-component-library.git
[email protected]:we_coder/vue3-component-library.git
we_coder
vue3-component-library
vue3-component-library
master

搜索帮助