diff --git a/.eslintignore b/.eslintignore index 1823be4770646252fe3929a9681467a751f44ec6..5fd8893668073906ee865c859133eb28624940a4 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,5 +3,5 @@ dist node_modules tests types -examples/static +examples/index.html coverage diff --git a/.gitignore b/.gitignore index 819aee42bf5ac17072587cce4ed60b09c91f05ed..1ba3564ceae262aa35d67bbe7c623f156d019557 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ lib -examples/static +dist + node_modules coverage diff --git a/esbuild.config.js b/esbuild.config.js index 212a6794a7744115a1ac2dc6dcbe9f20ef838e85..d4c23e97dd86ea2fbac8a97c321d3dbd66fe97c0 100644 --- a/esbuild.config.js +++ b/esbuild.config.js @@ -1,4 +1,4 @@ -import { build } from 'esbuild' +import { build, context } from 'esbuild' import vue from 'esbuild-plugin-vue' import progress from 'esbuild-plugin-progress' import { esbuildPluginFileSize } from 'esbuild-plugin-filesize' @@ -8,10 +8,8 @@ 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 isServe = process.argv.includes('serve') // 包名 const libraryName = 'fa-ui' const globalName = 'FaUI' @@ -32,6 +30,10 @@ async function buildLibrary () { '.ttf': 'file', '.woff': 'file' }, + define: { + '__VUE_OPTIONS_API__': 'true', + '__VUE_PROD_DEVTOOLS__': 'false' + }, plugins: [ esbuildStylePlugin({ postcss: { @@ -61,6 +63,10 @@ async function buildLibrary () { treeShaking: true, minify: true, external: ['vue'], + define: { + '__VUE_OPTIONS_API__': 'true', + '__VUE_PROD_DEVTOOLS__': 'false' + }, loader: { '.eot': 'file', '.svg': 'file', @@ -88,18 +94,24 @@ async function buildLibrary () { await build({ entryPoints: Object.values(components), - outdir: 'lib/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: { @@ -121,14 +133,13 @@ async function buildLibrary () { } // 打包预览页面 -function buildExamples () { - build({ +async function buildExamples () { + const ctx = await context({ entryPoints: ['examples/main.ts'], - outdir: 'examples/static', + outdir: 'dist/static', bundle: true, tsconfig: 'tsconfig.json', format: 'iife', - watch: true, sourcemap: true, loader: { '.eot': 'file', @@ -136,6 +147,10 @@ function buildExamples () { '.ttf': 'file', '.woff': 'file' }, + define: { + '__VUE_OPTIONS_API__': 'true', + '__VUE_PROD_DEVTOOLS__': 'false' + }, plugins: [ esbuildStylePlugin({ postcss: { @@ -151,20 +166,24 @@ function buildExamples () { }), vue(), progress(), + esbuildHtmlPlugin({ + template: 'examples/index.html', + filename: 'dist/index.html', + minify: true + }), esbuildPluginBowserSync({ - server: 'examples' + server: 'dist' }) ] }) + await ctx.watch() } // 启动函数 -async function start () { +(async (isServe) => { if (isServe) { buildExamples() } else { buildLibrary() } -} - -start() +})(process.argv.includes('serve')) diff --git a/examples/index.html b/examples/index.html index 02e551d8fb667edd5e84646aa23031a76414546e..66416676fd6c7d6bd34776dcfe17d56273243486 100644 --- a/examples/index.html +++ b/examples/index.html @@ -5,10 +5,8 @@