dpzvc-ui 1.2.0 → 1.2.2

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,8 +1,9 @@
1
1
  {
2
2
  "name": "dpzvc-ui",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Vue组件库",
5
5
  "main": "dist/dpzvc.js",
6
+ "module": "dist/dpzvc.esm.js",
6
7
  "scripts": {
7
8
  "init": "webpack --progress --config webpack.dev.config.js",
8
9
  "dev": "webpack serve --config webpack.dev.config.js --open",
@@ -1,52 +1,43 @@
1
1
  /**
2
- * Created by admin on 2017/5/8.
2
+ * messageGroup.js
3
+ * 兼容 Vue 2.7 runtime-only 构建
3
4
  */
4
5
 
5
- import MessageGroup from './messageGroup.vue'
6
6
  import Vue from 'vue';
7
- import {camelcaseToHyphen} from '../../utils/util'
8
-
9
- MessageGroup.newInstance = function (props) {
10
-
11
- let _props = props || {};
12
-
13
- let _prop = '';
14
- Object.keys(_props).forEach((prop) => {
15
-
16
- _prop += ' :' + camelcaseToHyphen(prop) + '=' + prop
17
- });
18
-
19
- let div = document.createElement('div');
20
-
21
- document.body.appendChild(div);
22
-
23
- let message = new Vue({
24
- el: div,
25
- data: _props,
26
- template:`<Message-group ${_prop} ></Message-group>`,
27
- components: {MessageGroup},
28
- }).$children[0];
29
-
30
-
31
- return {
32
-
33
- add(props){
34
- message.add(props)
35
- },
36
- remove(props) {
37
-
38
- message.remove(props)
39
- },
40
- component: message,
41
- destroy(){
42
- message.closeAll();
43
-
44
- setTimeout(()=>{
45
- document.body.removeChild(document.getElementsByClassName('dpzvc-message')[0].parentElement)
46
- },500)
47
-
48
- }
7
+ import MessageGroup from './messageGroup.vue'; // 你的 Vue 组件
8
+ import { camelcaseToHyphen } from '../../utils/util';
9
+
10
+ MessageGroup.newInstance = function (props = {}) {
11
+ const div = document.createElement('div');
12
+ document.body.appendChild(div);
13
+
14
+ // 使用 render 函数代替 template,兼容 runtime-only
15
+ const messageVm = new Vue({
16
+ data() {
17
+ return { ...props };
18
+ },
19
+ render(h) {
20
+ return h(MessageGroup, { props });
21
+ }
22
+ }).$mount(div);
23
+
24
+ const instance = messageVm.$children[0]; // 确保实例存在
25
+
26
+ return {
27
+ add(options) {
28
+ if (instance) instance.add(options);
29
+ },
30
+ remove(options) {
31
+ if (instance) instance.remove(options);
32
+ },
33
+ component: instance,
34
+ destroy() {
35
+ if (instance) instance.closeAll();
36
+ setTimeout(() => {
37
+ if (div.parentNode) div.parentNode.removeChild(div);
38
+ }, 500);
49
39
  }
50
- }
40
+ };
41
+ };
51
42
 
52
- export default MessageGroup;
43
+ export default MessageGroup;
@@ -1,8 +1,3 @@
1
- /**
2
- * webpack.dist.dev.config.js
3
- * 开发环境打包库文件 (Webpack 5)
4
- */
5
-
6
1
  const path = require('path');
7
2
  const webpack = require('webpack');
8
3
  const { merge } = require('webpack-merge');
@@ -10,7 +5,7 @@ const webpackBaseConfig = require('./webpack.base.config.js');
10
5
 
11
6
  process.env.NODE_ENV = 'production';
12
7
 
13
- module.exports = merge(webpackBaseConfig, {
8
+ module.exports =[merge(webpackBaseConfig, {
14
9
  mode: 'production',
15
10
 
16
11
  entry: {
@@ -46,4 +41,39 @@ module.exports = merge(webpackBaseConfig, {
46
41
  optimization: {
47
42
  minimize: false, // 开发库打包通常不压缩
48
43
  },
49
- });
44
+ }),
45
+ merge(webpackBaseConfig, {
46
+ mode: 'production',
47
+
48
+ entry: {
49
+ main: path.resolve(__dirname, './src/index.js')
50
+ },
51
+
52
+ output: {
53
+ path: path.resolve(__dirname, './dist'),
54
+ filename: 'dpzvc.esm.js', // 改名,标识 ESM
55
+ library: {
56
+ type: 'module' // ✅ 核心改动
57
+ },
58
+ clean: false
59
+ },
60
+
61
+ experiments: {
62
+ outputModule: true // ✅ 必须
63
+ },
64
+
65
+ externals: {
66
+ vue: 'vue'
67
+ },
68
+
69
+ plugins: [
70
+ new webpack.DefinePlugin({
71
+ 'process.env.NODE_ENV': JSON.stringify('production')
72
+ })
73
+ ],
74
+
75
+ optimization: {
76
+ concatenateModules: false,
77
+ minimize: false
78
+ }
79
+ })];
@@ -1,8 +1,3 @@
1
- /**
2
- * webpack.dist.prod.config.js
3
- * 生产环境打包库文件 (Webpack 5)
4
- */
5
-
6
1
  const path = require('path');
7
2
  const webpack = require('webpack');
8
3
  const TerserPlugin = require('terser-webpack-plugin');
@@ -11,7 +6,43 @@ const webpackBaseConfig = require('./webpack.base.config.js');
11
6
 
12
7
  process.env.NODE_ENV = 'production';
13
8
 
14
- module.exports = merge(webpackBaseConfig, {
9
+ module.exports =[
10
+ // -------- UMD 输出 --------
11
+ merge(webpackBaseConfig, {
12
+ mode: 'production',
13
+ entry: {
14
+ main: path.resolve(__dirname, './src/index.js')
15
+ },
16
+ output: {
17
+ path: path.resolve(__dirname, './dist'),
18
+ filename: 'dpzvc.min.js',
19
+ library: 'dpzvc',
20
+ libraryTarget: 'umd',
21
+ umdNamedDefine: true,
22
+ clean: false
23
+ },
24
+ externals: {
25
+ vue: 'Vue'
26
+ },
27
+ optimization: {
28
+ minimize: true,
29
+ minimizer: [
30
+ new TerserPlugin({
31
+ terserOptions: {
32
+ compress: { drop_console: true, drop_debugger: true },
33
+ output: { comments: false }
34
+ },
35
+ extractComments: false
36
+ })
37
+ ]
38
+ },
39
+ plugins: [
40
+ new webpack.DefinePlugin({
41
+ 'process.env.NODE_ENV': JSON.stringify('production')
42
+ })
43
+ ]
44
+ }),
45
+ merge(webpackBaseConfig, {
15
46
  mode: 'production',
16
47
 
17
48
  entry: {
@@ -20,34 +51,33 @@ module.exports = merge(webpackBaseConfig, {
20
51
 
21
52
  output: {
22
53
  path: path.resolve(__dirname, './dist'),
23
- publicPath: '/dist/',
24
- filename: 'dpzvc.min.js',
25
- library: 'dpzvc',
26
- libraryTarget: 'umd',
27
- umdNamedDefine: true,
28
- clean: false // webpack5 新增,每次构建清理旧文件
54
+ filename: 'dpzvc.esm.min.js', // ESM 文件
55
+ library: {
56
+ type: 'module' // 核心 ESM 输出
57
+ },
58
+ clean: false
59
+ },
60
+
61
+ experiments: {
62
+ outputModule: true
29
63
  },
30
64
 
31
65
  externals: {
32
- vue: {
33
- root: 'Vue',
34
- commonjs: 'vue',
35
- commonjs2: 'vue',
36
- amd: 'vue'
37
- }
66
+ vue: 'vue'
38
67
  },
39
68
 
40
69
  optimization: {
70
+ concatenateModules: false,
41
71
  minimize: true,
42
72
  minimizer: [
43
73
  new TerserPlugin({
44
74
  terserOptions: {
45
75
  compress: { drop_console: true, drop_debugger: true },
46
- output: { comments: false },
76
+ output: { comments: false }
47
77
  },
48
- extractComments: false, // 防止生成 LICENSE.txt
78
+ extractComments: false
49
79
  })
50
- ],
80
+ ]
51
81
  },
52
82
 
53
83
  plugins: [
@@ -55,4 +85,4 @@ module.exports = merge(webpackBaseConfig, {
55
85
  'process.env.NODE_ENV': JSON.stringify('production')
56
86
  })
57
87
  ]
58
- });
88
+ })];