Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: umd #847

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
84 changes: 84 additions & 0 deletions library-external.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { viteExternalsPlugin as ViteExternals } from 'vite-plugin-externals'
import { createHtmlPlugin } from 'vite-plugin-html'
import type { HtmlTagDescriptor } from 'vite'

import { dependencies } from './package.json'

/**
* It copies the external libraries to the `assets` folder, and injects the script tags into the HTML
*
* @param {boolean} isProduction - boolean
* @param {string} baseUrl - The base url of the application.
* @returns An array of plugins
*/
export const setupLibraryExternal = (
isProduction: boolean,
baseUrl: string,
) => {

const cdnUrl = 'https://unpkg.com/'

const staticTargets: { dev: string; prod: string }[] = [
{
dev: `./node_modules/vue/dist/vue.global${
isProduction ? '.prod' : ''
}.js`,
prod: `${cdnUrl}vue@${dependencies.vue}/dist/vue.global.prod.js`,
},
{
dev: `./node_modules/vue-router/dist/vue-router.global${
isProduction ? '.prod' : ''
}.js`,
prod: `${cdnUrl}vue-router@${dependencies['vue-router']}/dist/vue-router.global.prod.js`,
},

{
dev: `./node_modules/vue-demi/lib/index.iife.js`,
prod: `${cdnUrl}vue-demi@0.14.6/lib/index.iife.js`,
},
{
dev: './node_modules/@vueuse/shared/index.iife.min.js',
prod: `${cdnUrl}@vueuse/shared@${dependencies['@vueuse/shared']}/index.iife.min.js`,
},
{
dev: './node_modules/@vueuse/core/index.iife.min.js',
prod: `${cdnUrl}@vueuse/core@${dependencies['@vueuse/core']}/index.iife.min.js`,
},
{
dev: './node_modules/@vueuse/components/index.iife.min.js',
prod: `${cdnUrl}@vueuse/components@${dependencies['@vueuse/components']}/index.iife.min.js`,
},
]

const injectTags = staticTargets
.map((target) => {
return {
injectTo: 'head',
tag: 'script',
attrs: {
src: isProduction ? target.prod : target.dev,
type: 'text/javascript',
},
}
})
.filter(Boolean) as HtmlTagDescriptor[]

return [
ViteExternals({
vue: 'Vue',
'vue-router': 'VueRouter',

'@vueuse/core': 'VueUse',
'@vueuse/components': 'VueUse',

'vue-demi': 'VueDemi',
}),

createHtmlPlugin({
minify: false,
inject: {
tags: injectTags,
},
}),
]
}
244 changes: 125 additions & 119 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,120 +1,126 @@
{
"name": "mx-admin",
"version": "3.37.7",
"bump": {
"before": [
"git pull --rebase"
],
"changelog": true
},
"scripts": {
"prebuild": "rm -rf dist",
"dev": "NODE_ENV=development vite --mode development --open --host",
"build": "NODE_ENV=production vite build --mode production",
"preview": "vite preview --port 2323",
"lint": "eslint \"src/**/*.{ts,tsx,js,json,vue}\" --fix",
"format": "prettier --write --loglevel warn \"src/**/*.{js,json,tsx,ts,css,scss,vue,html,md}\""
},
"dependencies": {
"@antv/g2": "^4.2.10",
"@bytebase/vue-kbar": "0.1.8",
"@codemirror/commands": "6.3.3",
"@codemirror/lang-markdown": "6.2.4",
"@codemirror/language": "6.10.0",
"@codemirror/language-data": "6.4.0",
"@codemirror/state": "6.4.0",
"@codemirror/theme-one-dark": "6.1.2",
"@codemirror/view": "6.23.1",
"@ddietr/codemirror-themes": "1.4.2",
"@huacnlee/autocorrect": "2.9.0",
"@lezer/highlight": "^1.2.0",
"@mx-space/api-client": "1.7.2",
"@simplewebauthn/browser": "9.0.1",
"@types/canvas-confetti": "1.6.4",
"@vicons/antd": "0.12.0",
"@vicons/fa": "0.12.0",
"@vicons/fluent": "0.12.0",
"@vicons/ionicons4": "0.12.0",
"@vicons/ionicons5": "0.12.0",
"@vicons/material": "0.12.0",
"@vicons/tabler": "0.12.0",
"@vicons/utils": "0.1.4",
"@vueuse/core": "10.7.2",
"ansi_up": "6.0.2",
"buffer": "6.0.3",
"camelcase-keys": "9.1.3",
"canvas-confetti": "1.9.2",
"class-transformer": "0.5.1",
"class-validator": "0.14.1",
"crossbell.js": "npm:crossbell@1.9.0",
"date-fns": "3.3.1",
"ejs": "3.1.9",
"event-source-polyfill": "1.0.31",
"highlight.js": "11.9.0",
"js-cookie": "3.0.5",
"js-yaml": "4.1.0",
"json5": "2.2.3",
"lodash-es": "4.17.21",
"markdown-escape": "2.0.0",
"marked": "11.2.0",
"monaco-editor": "0.45.0",
"monaco-editor-auto-typings": "0.4.5",
"naive-ui": "2.37.3",
"octokit": "3.1.2",
"openai": "4.26.0",
"os-browserify": "0.3.0",
"path-browserify": "1.0.1",
"pinia": "2.1.7",
"qier-progress": "1.0.4",
"qs": "6.11.2",
"reflect-metadata": "0.2.1",
"socket.io-client": "4.7.4",
"sortablejs": "1.15.2",
"swrv": "1.0.4",
"umi-request": "1.4.0",
"unidata.js": "0.8.0",
"validator": "13.11.0",
"vite-plugin-windicss": "1.9.3",
"vue": "3.4.15",
"vue-router": "4.2.5",
"xss": "1.0.14",
"xterm": "5.3.0",
"xterm-addon-fit": "0.8.0",
"xterm-theme": "1.1.0"
},
"devDependencies": {
"@innei/eslint-config-vue-ts": "0.12.2",
"@innei/prettier": "0.12.2",
"@types/ejs": "3.1.5",
"@types/event-source-polyfill": "1.0.5",
"@types/js-yaml": "4.0.9",
"@types/lodash-es": "4.17.12",
"@types/markdown-escape": "1.1.3",
"@types/qs": "6.9.11",
"@types/sortablejs": "1.15.7",
"@types/validator": "13.11.8",
"@vitejs/plugin-vue": "5.0.3",
"@vitejs/plugin-vue-jsx": "3.1.0",
"@vue/compiler-sfc": "3.4.15",
"cors": "2.8.5",
"eslint": "^8.56.0",
"postcss": "8.4.33",
"postcss-nested": "6.0.1",
"postcss-preset-env": "9.3.0",
"prettier": "3.2.4",
"rollup": "^4.9.6",
"rollup-plugin-visualizer": "5.12.0",
"typescript": "5.3.3",
"unplugin-auto-import": "0.17.5",
"vite": "5.0.12",
"vite-plugin-checker": "0.6.4",
"vite-plugin-mkcert": "1.17.3",
"vite-plugin-wasm": "3.3.0",
"vite-tsconfig-paths": "4.3.1",
"vue-eslint-parser": "9.4.2",
"windicss": "3.5.6"
},
"resolutions": {
"@bytebase/vue-kbar>@vueuse/core": "^10.7.2"
}
}
"name": "mx-admin",
"version": "3.37.7",
"bump": {
"before": [
"git pull --rebase"
],
"changelog": true
},
"scripts": {
"prebuild": "rm -rf dist",
"dev": "NODE_ENV=development vite --mode development --open --host",
"build": "NODE_ENV=production vite build --mode production",
"preview": "vite preview --port 2323",
"lint": "eslint \"src/**/*.{ts,tsx,js,json,vue}\" --fix",
"format": "prettier --write --loglevel warn \"src/**/*.{js,json,tsx,ts,css,scss,vue,html,md}\""
},
"dependencies": {
"@antv/g2": "^4.2.10",
"@bytebase/vue-kbar": "0.1.8",
"@codemirror/commands": "6.3.3",
"@codemirror/lang-markdown": "6.2.4",
"@codemirror/language": "6.10.0",
"@codemirror/language-data": "6.4.0",
"@codemirror/state": "6.4.0",
"@codemirror/theme-one-dark": "6.1.2",
"@codemirror/view": "6.23.1",
"@ddietr/codemirror-themes": "1.4.2",
"@huacnlee/autocorrect": "2.9.0",
"@lezer/highlight": "^1.2.0",
"@mx-space/api-client": "1.7.2",
"@simplewebauthn/browser": "9.0.1",
"@types/canvas-confetti": "1.6.4",
"@vicons/antd": "0.12.0",
"@vicons/fa": "0.12.0",
"@vicons/fluent": "0.12.0",
"@vicons/ionicons4": "0.12.0",
"@vicons/ionicons5": "0.12.0",
"@vicons/material": "0.12.0",
"@vicons/tabler": "0.12.0",
"@vicons/utils": "0.1.4",
"@vueuse/core": "10.7.2",
"ansi_up": "6.0.2",
"buffer": "6.0.3",
"camelcase-keys": "9.1.3",
"canvas-confetti": "1.9.2",
"class-transformer": "0.5.1",
"class-validator": "0.14.1",
"crossbell.js": "npm:crossbell@1.9.0",
"date-fns": "3.3.1",
"ejs": "3.1.9",
"event-source-polyfill": "1.0.31",
"highlight.js": "11.9.0",
"js-cookie": "3.0.5",
"js-yaml": "4.1.0",
"json5": "2.2.3",
"lodash-es": "4.17.21",
"markdown-escape": "2.0.0",
"marked": "11.2.0",
"monaco-editor": "0.45.0",
"monaco-editor-auto-typings": "0.4.5",
"naive-ui": "2.37.3",
"octokit": "3.1.2",
"openai": "4.26.0",
"os-browserify": "0.3.0",
"path-browserify": "1.0.1",
"pinia": "2.1.7",
"qier-progress": "1.0.4",
"qs": "6.11.2",
"reflect-metadata": "0.2.1",
"socket.io-client": "4.7.4",
"sortablejs": "1.15.2",
"swrv": "1.0.4",
"umi-request": "1.4.0",
"unidata.js": "0.8.0",
"validator": "13.11.0",
"vite-plugin-windicss": "1.9.3",
"vue": "3.4.15",
"vue-demi": "*",
"vue-router": "4.2.5",
"xss": "1.0.14",
"xterm": "5.3.0",
"xterm-addon-fit": "0.8.0",
"xterm-theme": "1.1.0"
},
"devDependencies": {
"@innei/eslint-config-vue-ts": "0.12.2",
"@innei/prettier": "0.12.2",
"@types/ejs": "3.1.5",
"@types/event-source-polyfill": "1.0.5",
"@types/js-yaml": "4.0.9",
"@types/lodash-es": "4.17.12",
"@types/markdown-escape": "1.1.3",
"@types/qs": "6.9.11",
"@types/sortablejs": "1.15.7",
"@types/validator": "13.11.8",
"@vitejs/plugin-vue": "5.0.3",
"@vitejs/plugin-vue-jsx": "3.1.0",
"@vue/compiler-sfc": "3.4.15",
"@vueuse/components": "10.7.1",
"@vueuse/shared": "10.7.1",
"cors": "2.8.5",
"eslint": "^8.56.0",
"postcss": "8.4.33",
"postcss-nested": "6.0.1",
"postcss-preset-env": "9.3.0",
"prettier": "3.1.1",
"rollup": "^4.9.1",
"rollup-plugin-visualizer": "5.12.0",
"typescript": "5.3.3",
"unplugin-auto-import": "0.17.3",
"vite": "5.0.10",
"vite-plugin-checker": "0.6.2",
"vite-plugin-externals": "0.6.2",
"vite-plugin-html": "3.2.2",
"vite-plugin-mkcert": "1.17.3",
"vite-plugin-vue-devtools": "0.5.1",
"vite-plugin-wasm": "3.3.0",
"vite-tsconfig-paths": "4.3.1",
"vue-eslint-parser": "9.4.2",
"windicss": "3.5.6"
},
"resolutions": {
"@bytebase/vue-kbar>@vueuse/core": "^10.7.2"
}
}
41 changes: 41 additions & 0 deletions packages/plugin-bunder-kit/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { Plugin } from 'vite'

export function VitePluginBundlerKit(manifest: any): Plugin {
return {
name: 'plugin-bundler-kit',
config(config, env) {
return {
...config,
define: {
'process.env': process.env,
},
build: {
emptyOutDir: true,
lib: {
entry: 'src/index.ts',
name: manifest.metadata.name,
formats: ['iife'],
fileName: () => 'main.js',
},
rollupOptions: {
external: [
'vue',
'vue-router',
'@vueuse/core',
'@vueuse/components',
],
output: {
globals: {
vue: 'Vue',
'vue-router': 'VueRouter',
'@vueuse/core': 'VueUse',
'@vueuse/components': 'VueUse',
},
extend: true,
},
},
},
}
},
}
}
10 changes: 10 additions & 0 deletions plugins/hello/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Plugin</title>
<script src="./src/index.ts" type="module"></script>
</head>
<body></body>
</html>
Loading
Loading