| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- import { defineConfig } from 'vite'
- import vue from '@vitejs/plugin-vue'
- import eslint from 'vite-plugin-eslint'
- import viteCompression from 'vite-plugin-compression'
- import path from 'path'
- import fs from 'fs'
- import sizeOf from 'image-size'
- // 获取CAD图片大小
- const getImgSize = ()=> {
- try {
- const divs = path.resolve('./public/CAD_1')
- const fileName = fs.readdirSync(divs) as any
- if (!fileName || !fileName.length) return {}
- const max = Math.max(...fileName)
- const filePath = `${divs}/${max}`
- const filesPath = fs.readdirSync(filePath)
- const maxName = []
- for (let k = 0; k < filesPath.length; k++) {
- const el = filesPath[k]
- const id = el.indexOf('_')
- const num = el.substring(0, id)
- maxName.push({
- num,
- name: el
- })
- }
- maxName.sort((a, b) => +b.num - +a.num)
- const txt = `${divs}/${max}/${maxName[0].name}`
- const fileSize = sizeOf(txt)
- const obj = {
- W: fileSize.width * (+maxName[0].num + 1),
- H: fileSize.height * max,
- S: fileSize.width,
- M: max
- }
- return obj
- } catch (error) {
- return {W:0,H:0,S:0,M:0}
- }
- }
- // https://vitejs.dev/config/
- export default defineConfig({
- base: './',
- resolve: {
- alias: {
- /*
- 路径别名
- 若为文件系统路径必须是绝对路径的形式,否则将以别名原样呈现,不会解析为文件系统路径路径
- */
- '@': path.resolve(__dirname, './src')
- }
- },
- plugins: [vue(), viteCompression(), eslint({ fix: true, include: ['**/*.ts', '**/*.vue'] })],
- server: {
- host: '0.0.0.0',
- port: 8585,
- open: true,
- strictPort: false,
- https: false
- },
- esbuild: {
- drop: ['debugger'] //build 移除打印
- },
- build: {
- rollupOptions: {
- input: {
- index: path.resolve(__dirname, 'index.html')
- },
- output: { // 静态资源分类打包
- chunkFileNames: 'js/[hash].js',
- entryFileNames: 'js/[hash].js',
- assetFileNames: 'assets/[ext]/[hash].[ext]',
- // 拆分node_modules包
- manualChunks: (id: any) => {
- if (id.includes("node_modules")) {
- return id.toString().split("node_modules/")[1].split("/")[0].toString()
- }
- }
- }
- }
- },
- define: {
- 'process.env': {
- imgSize: getImgSize()
- },
- __VUE_OPTIONS_API__: true
- }
- })
|