Skip to content

Commit 651704d

Browse files
committed
fix: pdf文件预览内网兼容问题修复&&依赖包脆弱性修复
1 parent e492c00 commit 651704d

File tree

553 files changed

+11601
-10222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

553 files changed

+11601
-10222
lines changed

config/config.build.iframe.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
* @Author: zhanghan
33
* @Date: 2022-11-28 09:13:53
44
* @LastEditors: zhanghan
5-
* @LastEditTime: 2023-01-11 15:23:46
5+
* @LastEditTime: 2024-11-01
66
* @Descripttion: iframe开发环境配置
77
*/
88
const path = require('path')
99
const fs = require('fs-extra')
10+
const CopyWebpackPlugin = require('copy-webpack-plugin')
1011
// 获取基于当前路径的目标文件
1112
const resolve = (dir) => path.join(__dirname, '../', dir)
1213

@@ -71,5 +72,18 @@ module.exports = {
7172
})
7273
}
7374
})
75+
},
76+
// 配置 webpack 插件
77+
configureWebpack: {
78+
plugins: [
79+
// 复制 pdfjs-dist 的 cmaps 文件
80+
// copy-webpack-plugin 5.x 语法:直接传数组
81+
new CopyWebpackPlugin([
82+
{
83+
from: path.join(__dirname, '../node_modules/pdfjs-dist/cmaps'),
84+
to: path.join(__dirname, '../public/file-viewer/static/cmaps')
85+
}
86+
])
87+
]
7488
}
7589
}

config/config.build.js

Lines changed: 84 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,84 @@
1-
/*
2-
* @Author: zhanghan
3-
* @Date: 2022-11-28 09:13:53
4-
* @LastEditors: zhanghan
5-
* @LastEditTime: 2023-01-09 21:49:06
6-
* @Descripttion: 生产环境配置
7-
*/
8-
9-
const path = require('path')
10-
// 获取基于当前路径的目标文件
11-
const resolve = (dir) => path.join(__dirname, '../', dir)
12-
13-
const buildConfig = {
14-
// 输出文件目录
15-
outputDir: resolve('lib'),
16-
productionSourceMap: false,
17-
// webpack配置
18-
configureWebpack: {
19-
// 入口文件(这里获取到的是每个独立包的入口文件地址数组)
20-
entry: {
21-
// 全量引入的文件入口
22-
index: resolve('packages')
23-
},
24-
// 输出配置
25-
output: {
26-
// 主入口文件名称
27-
filename: '[name]/index.js',
28-
// 构建依赖类型
29-
libraryTarget: 'umd',
30-
// 库中被导出的项
31-
libraryExport: 'default',
32-
// 引用时的依赖名
33-
library: 'vue-file-viewer'
34-
}
35-
},
36-
css: {
37-
sourceMap: false,
38-
// 是否将组件中的css提取至一个独立的css,库构建时可以设置为false,免得用户需要自己导入css
39-
extract: false
40-
// extract: {
41-
// filename: '[name]/index.css',
42-
// },
43-
},
44-
chainWebpack: (config) => {
45-
// set worker-loader
46-
config.module
47-
.rule('worker')
48-
.test(/\.worker\.js$/)
49-
.use('worker-loader')
50-
.loader('worker-loader')
51-
.end()
52-
53-
// 解决:worker 热更新问题
54-
config.module.rule('js').exclude.add(/\.worker\.js$/)
55-
56-
// 一些构建优化
57-
// 删除splitChunks,因为每个组件是独立打包,不需要抽离每个组件的公共js出来。
58-
config.optimization.delete('splitChunks')
59-
// 删除copy,不要复制public文件夹内容到lib文件夹中。
60-
config.plugins.delete('copy')
61-
// 删除preload以及prefetch,因为不生成html页面,所以这两个也没用。
62-
config.plugins.delete('preload')
63-
config.plugins.delete('prefetch')
64-
// 删除html,只打包组件,不生成html页面。
65-
config.plugins.delete('html')
66-
// 删除hmr,删除热更新。
67-
config.plugins.delete('hmr')
68-
// 删除自动加上的入口App。
69-
config.entryPoints.delete('app')
70-
}
71-
}
72-
73-
module.exports = buildConfig
1+
/*
2+
* @Author: zhanghan
3+
* @Date: 2022-11-28 09:13:53
4+
* @LastEditors: zhanghan
5+
* @LastEditTime: 2024-11-01
6+
* @Descripttion: 生产环境配置
7+
*/
8+
9+
const path = require('path')
10+
const CopyWebpackPlugin = require('copy-webpack-plugin')
11+
// 获取基于当前路径的目标文件
12+
const resolve = (dir) => path.join(__dirname, '../', dir)
13+
14+
const buildConfig = {
15+
// 输出文件目录
16+
outputDir: resolve('lib'),
17+
productionSourceMap: false,
18+
// webpack配置
19+
configureWebpack: {
20+
// 入口文件(这里获取到的是每个独立包的入口文件地址数组)
21+
entry: {
22+
// 全量引入的文件入口
23+
index: resolve('packages')
24+
},
25+
// 输出配置
26+
output: {
27+
// 主入口文件名称
28+
filename: '[name]/index.js',
29+
// 构建依赖类型
30+
libraryTarget: 'umd',
31+
// 库中被导出的项
32+
libraryExport: 'default',
33+
// 引用时的依赖名
34+
library: 'vue-file-viewer'
35+
},
36+
plugins: [
37+
// 复制 pdfjs-dist 的 cmaps 文件
38+
// copy-webpack-plugin 5.x 语法:直接传数组
39+
new CopyWebpackPlugin([
40+
{
41+
from: path.join(__dirname, '../node_modules/pdfjs-dist/cmaps'),
42+
to: path.join(__dirname, '../lib/static/cmaps')
43+
}
44+
])
45+
]
46+
},
47+
css: {
48+
sourceMap: false,
49+
// 是否将组件中的css提取至一个独立的css,库构建时可以设置为false,免得用户需要自己导入css
50+
extract: false
51+
// extract: {
52+
// filename: '[name]/index.css',
53+
// },
54+
},
55+
chainWebpack: (config) => {
56+
// set worker-loader
57+
config.module
58+
.rule('worker')
59+
.test(/\.worker\.js$/)
60+
.use('worker-loader')
61+
.loader('worker-loader')
62+
.end()
63+
64+
// 解决:worker 热更新问题
65+
config.module.rule('js').exclude.add(/\.worker\.js$/)
66+
67+
// 一些构建优化
68+
// 删除splitChunks,因为每个组件是独立打包,不需要抽离每个组件的公共js出来。
69+
config.optimization.delete('splitChunks')
70+
// 删除copy,不要复制public文件夹内容到lib文件夹中。
71+
config.plugins.delete('copy')
72+
// 删除preload以及prefetch,因为不生成html页面,所以这两个也没用。
73+
config.plugins.delete('preload')
74+
config.plugins.delete('prefetch')
75+
// 删除html,只打包组件,不生成html页面。
76+
config.plugins.delete('html')
77+
// 删除hmr,删除热更新。
78+
config.plugins.delete('hmr')
79+
// 删除自动加上的入口App。
80+
config.entryPoints.delete('app')
81+
}
82+
}
83+
84+
module.exports = buildConfig

config/config.dev.js

Lines changed: 58 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,58 @@
1-
/*
2-
* @Author: zhanghan
3-
* @Date: 2022-11-28 09:13:53
4-
* @LastEditors: zhanghan
5-
* @LastEditTime: 2023-01-09 23:53:58
6-
* @Descripttion: 开发环境配置
7-
*/
8-
9-
module.exports = {
10-
pages: {
11-
index: {
12-
entry: 'examples/main.js',
13-
template: 'public/index.html',
14-
filename: 'index.html'
15-
}
16-
},
17-
// 扩展 webpack 配置
18-
chainWebpack: (config) => {
19-
// set worker-loader
20-
config.module
21-
.rule('worker')
22-
.test(/\.worker\.js$/)
23-
.use('worker-loader')
24-
.loader('worker-loader')
25-
.end()
26-
27-
// 解决:worker 热更新问题
28-
config.module.rule('js').exclude.add(/\.worker\.js$/)
29-
30-
// packages 加入编译
31-
config.module
32-
.rule('js')
33-
.include.add('/packages')
34-
.end()
35-
.use('babel')
36-
.loader('babel-loader')
37-
38-
// 别名配置
39-
config.resolve.alias.set('@', '/examples').set('@packages', '/packages')
40-
}
41-
}
1+
/*
2+
* @Author: zhanghan
3+
* @Date: 2022-11-28 09:13:53
4+
* @LastEditors: zhanghan
5+
* @LastEditTime: 2024-11-01
6+
* @Descripttion: 开发环境配置
7+
*/
8+
9+
const CopyWebpackPlugin = require('copy-webpack-plugin')
10+
const path = require('path')
11+
12+
module.exports = {
13+
pages: {
14+
index: {
15+
entry: 'examples/main.js',
16+
template: 'public/index.html',
17+
filename: 'index.html'
18+
}
19+
},
20+
// 扩展 webpack 配置
21+
chainWebpack: (config) => {
22+
// set worker-loader
23+
config.module
24+
.rule('worker')
25+
.test(/\.worker\.js$/)
26+
.use('worker-loader')
27+
.loader('worker-loader')
28+
.end()
29+
30+
// 解决:worker 热更新问题
31+
config.module.rule('js').exclude.add(/\.worker\.js$/)
32+
33+
// packages 加入编译
34+
config.module
35+
.rule('js')
36+
.include.add('/packages')
37+
.end()
38+
.use('babel')
39+
.loader('babel-loader')
40+
41+
// 别名配置
42+
config.resolve.alias.set('@', '/examples').set('@packages', '/packages')
43+
},
44+
45+
// 配置 webpack 插件
46+
configureWebpack: {
47+
plugins: [
48+
// 复制 pdfjs-dist 的 cmaps 文件到 public 目录
49+
// copy-webpack-plugin 5.x 语法:直接传数组
50+
new CopyWebpackPlugin([
51+
{
52+
from: path.join(__dirname, '../node_modules/pdfjs-dist/cmaps'),
53+
to: path.join(__dirname, '../public/static/cmaps')
54+
}
55+
])
56+
]
57+
}
58+
}

0 commit comments

Comments
 (0)