手搓vue3组件_0,打包配置

打包后引入项目是发现报错:

shell 复制代码
Cannot read properties of null (reading 'isCE')
TypeError: Cannot read properties of null (reading 'isCE')

这个是由于vue版本冲突问题,

这里我引入了自己打包的ui组件库,但是ui组件库中打包进入了自己的vue,那么在此时使用时,如果你引入的自己的组件中有slot,那么就会包这个问题,

解决方法千奇百怪

我的解决:

vue.config.js中加上:

javascript 复制代码
resolve: {
            symlinks: false,
            alias: {
                vue: path.resolve('./node_modules/vue')
            }
        },

那么它的完整配置就是:

javascript 复制代码
const { defineConfig } = require('@vue/cli-service')
// const webpack = require("webpack");
//打包配置自动忽略console.log等
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const path = require('path')

module.exports = defineConfig({
    productionSourceMap: false,
    transpileDependencies: true,
    publicPath: '/',
    //代理
    devServer: {
        // 指定项目启动时的默认端口号
        port: 80,
        historyApiFallback: true,
        allowedHosts: 'all',
        proxy: {
            '/': {
                ws: false,
                target: "http://localhost:89",
                changeOrigin: true,
                pathRewrite: {
                    '^/': '/'
                }
            }
        },
        // proxy: 'http://localhost:8090'
    },
    configureWebpack: {
        resolve: {
            symlinks: false,
            alias: {
                vue: path.resolve('./node_modules/vue')
            }
        },
        plugins: [
            //打包环境去掉console.log等
            /* @author icestone , 17:22
             * @date 2023/5/15
             * 下面这个应该在打包时才打开,开发时不要打开,编译消耗很多时间
            */
            /*new UglifyJsPlugin({
                uglifyOptions: {
                    compress: {
                        //warnings: false, 注释不然打包会报错如图下图
                        drop_console: true,  //注释console
                        drop_debugger: true, //注释debugger
                        pure_funcs: ['console.log'], //移除console.log
                    },
                },
            })*/
        ],
        output: {
            libraryExport: '../behind/src/static'
        },
    },
})
  • 当然,上面是在vue cli项目中的解决

关于这段配置的解释:

shell 复制代码
这段代码是用于配置 Webpack 的,它的目的是为了设置项目的别名和禁用符号链接。

resolve.symlinks: false:这一行设置为 false 表示禁用符号链接。符号链接是一种特殊的文件链接,它允许一个文件或目录链接到另一个文件或目录。在某些情况下,符号链接可能会导致问题,因此将其设置为 false 是合适的。

resolve.alias: { vue: path.resolve('./node_modules/vue') }:这一行设置了一个别名,它的作用是将 vue 模块解析为 ./node_modules/vue。这样,Webpack 就可以找到 Vue.js 库的入口文件,并且不会出现找不到模块的情况。path.resolve('./node_modules/vue') 是一个计算属性,它将当前项目的根路径与 vue 模块的路径进行拼接,得到 Vue.js 模块的完整路径。

总之,这段代码的作用是配置 Webpack 以禁用符号链接并设置 Vue.js 模块的别名。
  • 在vite项目中也是这样解决的,显式声明使用的vue位置:
javascript 复制代码
import { defineConfig } from 'vite'
import path from 'path'
import vue from '@vitejs/plugin-vue'


// https://vitejs.dev/config/
export default defineConfig({
    plugins: [vue()],
    resolve: {
        alias: {
            '@': path.resolve(__dirname, 'src'),
            vue: path.resolve('./node_modules/vue')
        }
    },
    css: {
        // 预处理器配置项
        preprocessorOptions: {
            less: {
                math: "always",
            },
        },
    },
    server: {
        proxy: {
            // 正则表达式写法
            '/api': {
                target: 'http://localhost:89',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, '')
            }
        }
    }
})
相关推荐
Fluxart.ai3 分钟前
GPT Image 2 国内怎么用?在 Flux Art 完成图片生成与编辑
前端·javascript·gpt
tanzongbiao6 分钟前
Dorado7文件上传 解决HttpServletResponse返回值中文乱码的问题
java·服务器·前端
郑州光合科技余经理4 小时前
本地生活服务系统:成品模块和定制接口怎么划界
java·前端·人工智能·后端·系统架构·php·ai编程
平头哥~8 小时前
Day 07 _ 那条 1px 的线,为什么在手机上忽粗忽细
前端·css·样式·学习资料
小江的记录本8 小时前
【CSS】CSS 动画:transition、animation、transform、CSS3 新特性(附《思维导图》)
前端·css·安全·spring·前端框架·css3·动画
circuitsosk8 小时前
任务规划器的三种范式对比:ReAct、Plan-and-Execute 与 Tree-of-Thought 在真实业务中的取舍
前端·javascript·python·react.js·llm·ai agent
hzxpaipai9 小时前
企业官网技术架构拆解:前端、后台、数据库、服务器如何协同
前端·数据库·架构
深念Y12 小时前
Lenovo XiaoXinAir 14 — 性能模式切换
前端·网络
计算机魔术师12 小时前
Meta突然杀进第一梯队:一个新模型,把AI推理成本打下来8倍
前端