app-form-view 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "app-form-view",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "vue表单组件库",
5
5
  "main": "dist/index.js",
6
6
  "publishConfig": {
@@ -24,6 +24,7 @@
24
24
  "license": "ISC",
25
25
  "devDependencies": {
26
26
  "@babel/core": "^7.20.7",
27
+ "@babel/plugin-proposal-optional-chaining": "^7.21.0",
27
28
  "@babel/preset-env": "^7.20.2",
28
29
  "@rollup/plugin-alias": "^4.0.2",
29
30
  "@rollup/plugin-babel": "^6.0.3",
@@ -35,20 +36,21 @@
35
36
  "@rollup/plugin-terser": "^0.4.4",
36
37
  "@vue/babel-helper-vue-jsx-merge-props": "^1.4.0",
37
38
  "@vue/babel-plugin-transform-vue-jsx": "^1.4.0",
38
- "autoprefixer": "^10.4.13",
39
+ "autoprefixer": "^10.5.0",
39
40
  "body-parser": "^1.20.2",
40
41
  "express": "^4.18.2",
41
42
  "glob": "^8.1.0",
42
43
  "http-proxy-middleware": "^3.0.5",
43
44
  "node-sass": "^6.0.1",
45
+ "postcss": "^8.5.15",
44
46
  "rollup": "^2.79.1",
45
47
  "rollup-plugin-copy": "^3.5.0",
46
48
  "rollup-plugin-filesize": "^9.1.2",
47
49
  "rollup-plugin-livereload": "^2.0.5",
48
- "rollup-plugin-postcss": "^4.0.2",
50
+ "rollup-plugin-scss": "^4.0.1",
49
51
  "rollup-plugin-serve": "^2.0.2",
50
52
  "rollup-plugin-vue2": "^0.8.1",
51
- "sass": "^1.100.0",
53
+ "sass": "^1.101.0",
52
54
  "sass-loader": "^7.0.3",
53
55
  "uglify-es": "^3.3.9",
54
56
  "vuepress": "^1.9.8",
@@ -62,7 +64,7 @@
62
64
  "js-beautify": "^1.15.4",
63
65
  "jszip": "^3.10.1",
64
66
  "lodash": "^4.17.21",
65
- "rollup-plugin-scss": "^4.0.1",
67
+ "rollup-plugin-postcss": "^4.0.2",
66
68
  "vant": "^2.12.14",
67
69
  "vue": "^2.6.14",
68
70
  "vue-template-compiler": "^2.6.14",
@@ -3,81 +3,113 @@ import resolve from "@rollup/plugin-node-resolve"
3
3
  import commonjs from "@rollup/plugin-commonjs"
4
4
  import copy from 'rollup-plugin-copy';
5
5
  import json from '@rollup/plugin-json'
6
- import scss from "rollup-plugin-scss"
7
6
  import alias from '@rollup/plugin-alias'
8
7
  import vue from 'rollup-plugin-vue2'
9
8
  import image from '@rollup/plugin-image'
10
9
  import replace from '@rollup/plugin-replace'
10
+ // 新增postcss,移除scss导入
11
+ import postcss from "rollup-plugin-postcss"
11
12
  const path = require('path')
12
13
 
13
14
  const customResolver = resolve({
14
15
  extensions: ['.mjs', '.js', '.jsx', '.json', '.sass', '.scss']
15
16
  });
16
17
 
17
- export default {
18
- input: "src/index.js",
19
- //external: ['vue'],
20
- plugins: [
21
- alias({
22
- entries: [
23
- { find: '@', replacement: path.resolve(__dirname, '../src') },
24
- ],
25
- customResolver
26
- }),
27
- replace({
28
- // 关键:必须用 JSON.stringify 包裹,且值为 process.env.NODE_ENV(从命令行传递)
29
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
30
- preventAssignment: true,
31
- }),
32
- vue({
33
- // 解析 template 模板
34
- template: {
35
- compiler: require('vue-template-compiler'), // 显式指定编译器
36
- compilerOptions: {
37
- preserveWhitespace: false
38
- }
39
- },
40
- //css: true, // 👈 改成 true
41
- // 处理样式(交给 postcss)
42
- css: false
43
- }),
44
- scss({
45
- fileName: "css/style.css",
46
- failOnError: true,
47
- sourceMap: false,
48
- }),
49
- resolve({
50
- extensions: ['.js', '.vue', '.json'],
51
- preferBuiltins: false
52
- }),
53
- commonjs({
54
- include: "node_modules/**",
55
- }),
56
- babel({
57
- exclude: 'node_modules/**',
58
- extensions: ['.js', '.vue', '.jsx'], // 明确支持的文件类型
59
- babelHelpers: 'bundled',
60
- presets: [
61
- ['@babel/preset-env', {
62
- targets: 'last 2 versions, > 1%, not dead'
63
- }]
64
- ],
65
- plugins: [
66
- '@babel/plugin-syntax-jsx',
67
- '@vue/babel-plugin-transform-vue-jsx'
68
- ]
69
- }),
70
- json(),
71
- image(),
72
- copy({
73
- targets: [
74
- {
75
- src: 'node_modules/element-ui/lib/theme-chalk/fonts/*', // 源文件路径(Element UI 的字体文件)
76
- dest: 'dist/fonts' // 目标路径(复制到 dist/fonts 目录下)
77
- }
78
- ],
79
- // 可选:如果目标目录已存在,覆盖旧文件
80
- overwrite: true
81
- })
82
- ]
83
- };
18
+ /**
19
+ * 工厂生成基础配置
20
+ * @param {string} cssOutputName css输出完整路径/文件名
21
+ * @returns Rollup基础配置
22
+ */
23
+ function createBaseConfig(cssOutputName = "form-design.css") {
24
+ return {
25
+ input: "src/index.js",
26
+ external: ['vue', 'vuex', 'element-ui', 'vant'],
27
+ output: {
28
+ globals: {
29
+ vue: 'Vue',
30
+ vuex: 'Vuex',
31
+ 'element-ui': 'ELEMENT',
32
+ vant: 'vant'
33
+ }
34
+ },
35
+ plugins: [
36
+ alias({
37
+ entries: [
38
+ { find: '@', replacement: path.resolve(__dirname, '../src') },
39
+ ],
40
+ customResolver
41
+ }),
42
+ replace({
43
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
44
+ preventAssignment: true,
45
+ }),
46
+ vue({
47
+ template: {
48
+ compiler: require('vue-template-compiler'),
49
+ compilerOptions: {
50
+ preserveWhitespace: false
51
+ }
52
+ },
53
+ css: false,
54
+ scoped: true
55
+ }),
56
+ // 替换原来的 scss 插件
57
+ postcss({
58
+ extract: cssOutputName,
59
+ use: ["sass"], // 解析 lang="scss"
60
+ plugins: [
61
+ require("autoprefixer")()
62
+ ],
63
+ sourceMap: false
64
+ }),
65
+ resolve({
66
+ extensions: ['.js', '.vue', '.json'],
67
+ preferBuiltins: false
68
+ }),
69
+ commonjs({
70
+ include: "node_modules/**",
71
+ }),
72
+ babel({
73
+ exclude: 'node_modules/**',
74
+ extensions: ['.js', '.vue', '.jsx'],
75
+ babelHelpers: 'bundled',
76
+ presets: [
77
+ [
78
+ '@babel/preset-env',
79
+ {
80
+ targets: {
81
+ ie: 11,
82
+ chrome: 49,
83
+ safari: 10
84
+ },
85
+ modules: false,
86
+ useBuiltIns: false
87
+ }
88
+ ]
89
+ ],
90
+ plugins: [
91
+ '@babel/plugin-syntax-jsx',
92
+ '@vue/babel-plugin-transform-vue-jsx',
93
+ '@babel/plugin-proposal-optional-chaining'
94
+ ]
95
+ }),
96
+ json(),
97
+ image(),
98
+ copy({
99
+ targets: [
100
+ {
101
+ src: 'node_modules/element-ui/lib/theme-chalk/fonts/*',
102
+ dest: 'dist/fonts'
103
+ }
104
+ ],
105
+ overwrite: true
106
+ })
107
+ ],
108
+ onwarn(warning, warn) {
109
+ if (warning.code === 'CIRCULAR_DEPENDENCY') return
110
+ if (warning.message.includes('stream')) return
111
+ warn(warning)
112
+ }
113
+ }
114
+ }
115
+ export default createBaseConfig;
@@ -1,54 +1,57 @@
1
-
2
- import replace from '@rollup/plugin-replace';
3
1
  import path from "path";
4
2
  const glob = require("glob")
5
3
  const list = {};
6
- async function makeList(dirpath, list) {
4
+
5
+ function makeList(dirpath, list) {
7
6
  const files = glob.sync(dirpath + '/**/app-index.js')
8
7
  for (let file of files) {
9
8
  const component = 'index'
10
9
  list[component] = file
11
10
  }
12
-
13
11
  }
14
12
  makeList('src', list)
13
+
15
14
  import filesize from "rollup-plugin-filesize";
16
15
  import terser from '@rollup/plugin-terser';
17
- import baseConfig from "./rollup.config.base.js";
16
+ import createBaseConfig from "./rollup.config.base.js";
18
17
  import { name, version } from "../package.json";
19
- // banner
18
+
20
19
  const banner =
21
- `${"/*!\n" + " * "}${name}.js v${version}\n` +
22
- " * Released under the MIT License.\n" +
23
- " */";
24
- const external = ['vue', 'element-ui', 'util', 'vant', 'vuex'];
20
+ `/*!
21
+ * ${name}.js v${version}
22
+ * Released under the MIT License.
23
+ */`;
24
+
25
+ const external = ['vue', 'element-ui', 'vant', 'vuex'];
25
26
  const globals = {
26
27
  'vuex': 'Vuex',
27
28
  'vue': 'Vue',
28
29
  'vant': 'vant',
29
- 'element-ui': 'ELEMENT',
30
- 'util': 'util'
30
+ 'element-ui': 'ELEMENT'
31
31
  };
32
- // 支持输出 []
33
- baseConfig.input = list
32
+
33
+ // 调用工厂函数,指定css输出路径,不要手动改base原始对象
34
+ const baseConfig = createBaseConfig("css/style.css");
35
+ baseConfig.input = 'src/app-index.js'
36
+
34
37
  export default [
35
- // .js, .cjs.js, .esm.js
36
38
  {
37
39
  ...baseConfig,
38
40
  external,
39
- output: [
40
- // umd development version with sourcemap
41
- {
42
- dir: `dist`,
43
- name,
44
- banner,
45
- assetFileNames: 'style.css',
46
- format: 'umd',
47
- globals
48
- },
49
-
41
+ output: {
42
+ file: "dist/index.js",
43
+ banner,
44
+ format: 'umd',
45
+ globals,
46
+ name: "AppFormView",
47
+ },
48
+ // 重点:删掉外层的 scss 实例,只追加压缩插件
49
+ plugins: [
50
+ ...baseConfig.plugins,
51
+ terser({
52
+ format: { comments: 'all' }
53
+ }),
54
+ filesize()
50
55
  ],
51
- plugins: [...baseConfig.plugins, terser(), filesize()],
52
56
  }
53
- ];
54
-
57
+ ];
@@ -1,32 +1,29 @@
1
1
  import livereload from "rollup-plugin-livereload";
2
- import baseConfig from "./rollup.config.base.js";
2
+ import createBaseConfig from "./rollup.config.base.js";
3
3
  import { name } from "../package.json";
4
4
  import express from 'express';
5
5
  import { createProxyMiddleware } from 'http-proxy-middleware';
6
- import replace from '@rollup/plugin-replace';
7
6
  const glob = require("glob");
8
7
  const list = {};
9
8
 
10
- // 修复1:正确提取组件路径+修复模板字符串语法错误
11
- async function makeList(dirpath, list) {
9
+ // 移除无用 async
10
+ function makeList(dirpath, list) {
12
11
  const files = glob.sync(dirpath + '/**/index.js');
13
12
  for (let file of files) {
14
- // 提取组件路径(如 src/components/button/index.js → button)
15
13
  const component = file.split(/[/.]/).slice(-3, -1).join('/');
16
- list[component] = file; // 移除多余的 ${},避免字符串拼接错误
14
+ list[component] = file;
17
15
  }
18
16
  }
19
17
  makeList('src/components/', list);
20
18
 
21
- // 启动 Express 服务器
19
+ // 启动 Express 开发服务
22
20
  const app = express();
23
- const localIP = 'localhost'; // 固定本地IP(已替换)
24
- const proxyTarget = `http://${localIP}:8088`; // 代理目标IP
21
+ const localIP = 'localhost';
22
+ const proxyTarget = `http://${localIP}:8082`;
25
23
 
26
- // 静态文件服务
27
24
  app.use(express.static('.'));
28
25
 
29
- // 代理中间件(目标已改为固定IP)
26
+ // API 代理
30
27
  app.use('/api', createProxyMiddleware({
31
28
  target: proxyTarget,
32
29
  changeOrigin: true,
@@ -39,15 +36,17 @@ app.use('/api', createProxyMiddleware({
39
36
  }
40
37
  }));
41
38
 
42
- // 修复2:控制台日志显示正确的IP地址(而非localhost)
43
39
  app.listen(8006, localIP, () => {
44
- console.log(`🚀 开发服务器已启动: http://${localIP}:8006`); // 显示IP访问地址
45
- console.log(`🔀 代理配置: /api/* -> ${proxyTarget}/api/*`); // 显示正确代理目标
40
+ console.log(`🚀 开发服务器已启动: http://${localIP}:8006`);
41
+ console.log(`🔀 代理配置: /api/* -> ${proxyTarget}/api/*`);
46
42
  });
47
43
 
44
+ // 1. 通过工厂生成全新独立配置,指定开发环境CSS输出路径
45
+ const devBase = createBaseConfig();
46
+
48
47
  export default [
49
48
  {
50
- ...baseConfig,
49
+ ...devBase,
51
50
  output: [
52
51
  {
53
52
  file: `dist/${name}.js`,
@@ -56,15 +55,13 @@ export default [
56
55
  },
57
56
  ],
58
57
  plugins: [
59
- ...baseConfig.plugins,
60
- replace({ // 新增插件
61
- __API_PROXY_TARGET__: JSON.stringify(proxyTarget),
62
- preventAssignment: true
63
- }),
58
+ ...devBase.plugins,
59
+ // 删除外层 scss、删除外层重复 replace!base 已内置
60
+ // 仅追加开发专属热更新插件
64
61
  livereload({
65
62
  watch: '.',
66
63
  port: 35729,
67
- host: localIP // 修复3:livereload绑定本地IP,避免局域网热更新失效
64
+ host: localIP
68
65
  })
69
66
  ],
70
67
  },
@@ -3,7 +3,7 @@ import terser from "@rollup/plugin-terser";
3
3
  import baseConfig from "./rollup.config.base.js";
4
4
  import { name as packageName, version } from "../package.json";
5
5
  import path from "path";
6
-
6
+ import scss from "rollup-plugin-scss"
7
7
  // banner 保持不变
8
8
  const banner =
9
9
  `${"/*!\n" + " * "}${packageName}.js v${version}\n` +
@@ -62,12 +62,17 @@ function generateRollupConfigs() {
62
62
  globals
63
63
  }
64
64
  ],
65
- plugins: [...baseConfig.plugins, filesize()]
65
+ plugins: [...baseConfig.plugins, scss({
66
+ fileName: "form-design.css",
67
+ failOnError: true,
68
+ //sourceMap: false,
69
+ }), filesize()]
66
70
  });
67
71
 
68
72
  // --- 压缩版配置(.min.js)---
69
73
  configs.push({
70
74
  ...baseConfig,
75
+
71
76
  input: entryPath, // 动态设置入口文件
72
77
  external,
73
78
  output: [
@@ -81,6 +86,11 @@ function generateRollupConfigs() {
81
86
  ],
82
87
  plugins: [
83
88
  ...baseConfig.plugins,
89
+ scss({
90
+ fileName: "form-design.css",
91
+ failOnError: true,
92
+ //sourceMap: false,
93
+ }),
84
94
  terser({
85
95
  compress: {
86
96
  drop_console: false,
package/src/app-index.js CHANGED
@@ -1,65 +1,82 @@
1
1
  import Vue from 'vue'
2
2
  import '@/assets/scss/app-form.scss'
3
- // 只导入自己的组件
4
3
  import viewAppForm from '@/views/build/viewAppForm.vue'
4
+ // 全部导入改名
5
+ import _AppForm from '@/components/appForm/Form.vue'
6
+ import _AppFormItem from '@/components/appForm/Formitem.vue'
7
+ import _AppSubRow from '@/components/appForm/SubRow.vue'
8
+ import _AppInput from '@/components/appForm/Input.vue'
9
+ import _AppTextBox from '@/components/appForm/TextBox.vue'
10
+ import _AppInputHidden from '@/components/appForm/InputHidden.vue'
11
+ import _AppSelect from '@/components/appForm/Select.vue'
12
+ import _AppRadio from '@/components/appForm/Radio.vue'
13
+ import _AppCheckbox from '@/components/appForm/Checkbox.vue'
14
+ import _AppDateTimePicker from '@/components/appForm/DateTimePicker.vue'
15
+ import _AppDateTimeRange from '@/components/appForm/DateTimePickers.vue'
16
+ import _AppInputTree from '@/components/appForm/inputTree.vue'
17
+ import _AppInputUpload from '@/components/appForm/InputUpload.vue'
18
+ import _AppSearchSelect from '@/components/appForm/SearchSelect.vue'
19
+ import _AppSearchApi from '@/components/appForm/SearchApi.vue'
20
+ import _AppSubTitle from '@/components/appForm/SubTitle.vue'
21
+ import _AppTable from '@/components/appForm/Table.vue'
22
+ import _AppButton from '@/components/appForm/Button.vue'
23
+ import _AppLayoutBlock from './components/appForm/LayoutBlock.vue'
5
24
 
6
- // 内部子组件 —— 只供 viewAppForm 内部使用,不对外!
7
- import AppForm from '@/components/appForm/Form.vue'
8
- import AppFormItem from '@/components/appForm/Formitem.vue'
9
- import AppSubRow from '@/components/appForm/SubRow.vue'
10
- import AppInput from '@/components/appForm/Input.vue'
11
- import AppTextBox from '@/components/appForm/TextBox.vue'
12
- import AppInputHidden from '@/components/appForm/InputHidden.vue'
13
- import AppSelect from '@/components/appForm/Select.vue'
14
- import AppRadio from '@/components/appForm/Radio.vue'
15
- import AppCheckbox from '@/components/appForm/Checkbox.vue'
16
- import AppDateTimePicker from '@/components/appForm/DateTimePicker.vue'
17
- import AppDateTimeRange from '@/components/appForm/DateTimePickers.vue'
18
- import AppInputTree from '@/components/appForm/inputTree.vue'
19
- import AppInputUpload from '@/components/appForm/InputUpload.vue'
20
- import AppSearchSelect from '@/components/appForm/SearchSelect.vue'
21
- import AppSearchApi from '@/components/appForm/SearchApi.vue'
22
- import AppSubTitle from '@/components/appForm/SubTitle.vue'
23
- import AppTable from '@/components/appForm/Table.vue'
24
- import AppButton from '@/components/appForm/Button.vue'
25
- import AppLayoutBlock from './components/appForm/LayoutBlock.vue'
26
-
27
- // 内部组件列表
28
- const innerComponents = [
29
- AppForm,
30
- AppFormItem,
31
- AppSubRow,
32
- AppInput,
33
- AppTextBox,
34
- AppInputHidden,
35
- AppSelect,
36
- AppRadio,
37
- AppCheckbox,
38
- AppDateTimePicker,
39
- AppDateTimeRange,
40
- AppInputTree,
41
- AppInputUpload,
42
- AppSearchSelect,
43
- AppSearchApi,
44
- AppSubTitle,
45
- AppTable,
46
- AppButton,
47
- AppLayoutBlock
48
- ]
25
+ const components = {
26
+ AppFormView: viewAppForm,
27
+ AppForm: _AppForm,
28
+ AppFormItem: _AppFormItem,
29
+ AppSubRow: _AppSubRow,
30
+ AppInput: _AppInput,
31
+ AppTextBox: _AppTextBox,
32
+ AppInputHidden: _AppInputHidden,
33
+ AppSelect: _AppSelect,
34
+ AppRadio: _AppRadio,
35
+ AppCheckbox: _AppCheckbox,
36
+ AppDateTimePicker: _AppDateTimePicker,
37
+ AppDateTimeRange: _AppDateTimeRange,
38
+ AppInputTree: _AppInputTree,
39
+ AppInputUpload: _AppInputUpload,
40
+ AppSearchSelect: _AppSearchSelect,
41
+ AppSearchApi: _AppSearchApi,
42
+ AppSubTitle: _AppSubTitle,
43
+ AppTable: _AppTable,
44
+ AppButton: _AppButton,
45
+ AppLayoutBlock: _AppLayoutBlock
46
+ }
49
47
 
50
- // 安装插件:只对外暴露 viewAppForm
51
48
  const install = function (Vue) {
52
49
  if (install.installed) return
53
-
54
- // 1. 注册内部子组件(给 viewAppForm 使用)
55
- innerComponents.forEach(comp => {
50
+ install.installed = true
51
+ Object.values(components).forEach(comp => {
56
52
  Vue.component(comp.name, comp)
57
53
  })
54
+ }
58
55
 
59
- // 2. 只对外导出这一个主组件
60
- Vue.component(viewAppForm.name, viewAppForm)
56
+ const AppFormPlugin = {
57
+ install,
58
+ ...components
61
59
  }
60
+ export default AppFormPlugin
62
61
 
63
- export default {
64
- install
65
- }
62
+ // 现在导出变量名和导入别名不冲突,正常编译
63
+ export const AppFormView = components.AppFormView
64
+ export const AppForm = components.AppForm
65
+ export const AppFormItem = components.AppFormItem
66
+ export const AppSubRow = components.AppSubRow
67
+ export const AppInput = components.AppInput
68
+ export const AppTextBox = components.AppTextBox
69
+ export const AppInputHidden = components.AppInputHidden
70
+ export const AppSelect = components.AppSelect
71
+ export const AppRadio = components.AppRadio
72
+ export const AppCheckbox = components.AppCheckbox
73
+ export const AppDateTimePicker = components.AppDateTimePicker
74
+ export const AppDateTimeRange = components.AppDateTimeRange
75
+ export const AppInputTree = components.AppInputTree
76
+ export const AppInputUpload = components.AppInputUpload
77
+ export const AppSearchSelect = components.AppSearchSelect
78
+ export const AppSearchApi = components.AppSearchApi
79
+ export const AppSubTitle = components.AppSubTitle
80
+ export const AppTable = components.AppTable
81
+ export const AppButton = components.AppButton
82
+ export const AppLayoutBlock = components.AppLayoutBlock