diff --git a/build/ViteSingleCssPlugin.js b/build/ViteSingleCssPlugin.js new file mode 100644 index 0000000..46e7e2c --- /dev/null +++ b/build/ViteSingleCssPlugin.js @@ -0,0 +1,29 @@ +let packageNames = [] +let viteConfig +let IIFEcss + +// 将 css 打包到 js 文件中 +export default function() { + return { + apply: 'build', + enforce: 'post', + name: 'pack-css', + configResolved(config) { + viteConfig = config + packageNames = viteConfig.build.lib.formats.map(format => viteConfig.build.lib.fileName(format)) + }, + generateBundle(_, bundle) { + const cssFileName = 'style.css' + const { [cssFileName]: cssBundle } = bundle + if (cssBundle) { + IIFEcss = `(function() {try {var elementStyle = document.createElement('style');elementStyle.innerText = ${JSON.stringify(cssBundle.source)};document.head.appendChild(elementStyle);} catch(error) {console.error(error, 'unable to concat style inside the bundled file')}})()` + delete bundle[cssFileName] + } + packageNames.forEach(packageName => { + if (bundle[packageName]) { + bundle[packageName].code += IIFEcss + } + }) + } + } +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..38decd5 --- /dev/null +++ b/index.html @@ -0,0 +1,13 @@ + + + + + + + vue-dynamic-form-component + + +
+ + + \ No newline at end of file diff --git a/package.json b/package.json index b0ff596..4cc9cb6 100644 --- a/package.json +++ b/package.json @@ -18,12 +18,19 @@ "url": "https://github.com/chenquincy/vue-dynamic-form-component" }, "scripts": { - "dev": "vue-cli-service serve", - "build": "vue-cli-service build --target lib --dest lib --name vue-dynamic-form-component ./packages/index.js", + "dev": "vite", + "build": "vite build", "docs:dev": "vuepress dev docs", "docs:build": "vuepress build docs" }, - "main": "./lib/vue-dynamic-form-component.umd.min.js", + "main": "./lib/vue-dynamic-form-component.umd.js", + "module": "./lib/vue-dynamic-form-component.es.js", + "exports": { + ".": { + "import": "./lib/vue-dynamic-form-component.es.js", + "require": "./lib/vue-dynamic-form-component.umd.js" + } + }, "typings": "types/index.d.ts", "vetur": { "tags": "vetur/tags.json", @@ -44,7 +51,11 @@ "eslint": "^5.16.0", "eslint-plugin-vue": "^5.0.0", "node-sass": "^4.9.0", + "sass": "^1.49.9", "sass-loader": "^7.1.0", + "vite": "^2.8.6", + "vite-plugin-eslint": "^1.3.0", + "vite-plugin-vue2": "^1.9.3", "vue": "^2.6.10", "vue-template-compiler": "^2.6.10", "vuepress": "^1.0.1", diff --git a/packages/dynamic-form-item/form-item.vue b/packages/dynamic-form-item/form-item.vue index 50cc774..b89d27b 100644 --- a/packages/dynamic-form-item/form-item.vue +++ b/packages/dynamic-form-item/form-item.vue @@ -102,7 +102,7 @@