Vue CLI

vue-cli3+工具中,配置路径别名(vue.config.js)

别来无恙 提交于 2019-11-25 22:06:24
vue-cli 2.x 版本创建项目时,我们可以在 build 文件夹下找到 webpack.base.conf.js 文件,在里面修改 resolve.alias 即可。 resolve: { extensions: ['.js', '.vue', '.json'], alias: { 'vue$': 'vue/dist/vue.esm.js', '@': resolve('src'), } }, 但是vue-cli 3.0 创建项目时,目录结构精简化,找不到 build 和 config 文件夹,那么该如何修改路径别名呢? 只需要在项目根目录下,新建vue.config.js文件,代码如下: const path = require('path');//引入path模块 function resolve(dir){ return path.join(__dirname,dir)//path.join(__dirname)设置绝对路径 } module.exports={ chainWebpack:(config)=>{ config.resolve.alias //set第一个参数:设置的别名,第二个参数:设置的路径 .set('@',resolve('./src')) .set('components',resolve('./src/components')) .set(

Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#<Object>‘的解决方法

百般思念 提交于 2019-11-25 17:02:48
出现如题的错误时 网络上的解决办法:点开错误的文件,标注错误的地方是这样的一段代码: import {normalTime} from './timeFormat'; module.exports={   normalTime }; 解决方法 通过谷歌查找,和论坛各种搜索: 原因如下: The code above is ok. You can mix require and export. You can‘t mix import and module.exports. 翻译过来就是说,代码没毛病,在webpack打包的时候,可以在js文件中混用require和export。但是不能混用import 以及 module.exports 。 因为webpack 2中不允许混用import和 module.exports 解决办法就是统一改成ES6的方式编写即可. import {normalTime} from './timeFormat'; export default normalTime; 如以上可以解决问题,就不用往下看了,如不能解决问题往下看 如果出现的是install任何文件都会出现这个错误,怎么改都不行的话,就是版本的问题了。 项目的版本是旧版的,install的是最新的版本就会出现错误,只需要修改版本号就可以了。 用vue-cli脚手架默认是生成vue 2.x的版本