2***@qq.com
2***@qq.com
  • 发布:2021-04-16 10:23
  • 更新:2021-04-16 10:23
  • 阅读:1947

【报Bug】uni-app使用vue.conifg.js配置路径别名报错

分类:uni-app

产品分类: uniapp/H5

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10

HBuilderX类型: 正式

HBuilderX版本号: 3.1.9

浏览器平台: Chrome

浏览器版本: 89.0.4389.128

项目创建方式: HBuilderX

操作步骤:

见bug描述

预期结果:

无报错

实际结果:

见bug描述

bug描述:

// vue.config.js  
const path = require('path')  
const CopyWebpackPlugin = require('copy-webpack-plugin') //最新版本copy-webpack-plugin插件暂不兼容,推荐v5.0.0  
const webpack = require('webpack')  
const resolve = dir => path.join(__dirname, dir)  

module.exports = {  
    configureWebpack: {  
        plugins: [  
            new CopyWebpackPlugin([{  
                from: resolve('static/images'),  
                to: path.join(__dirname, 'dist', process.env.NODE_ENV === 'production' ? 'build' : 'dev', process.env.UNI_PLATFORM,  
                    'images')  
            }])  
        ],  
    },  
    chainWebpack: (config) => {  
        config.resolve.alias // 添加别名  
            .set('@pages', resolve('pages'))  
            .set('@common', resolve('common'))  
            .set('@static', resolve('static'))  
            .set('@images', resolve('static/images'))  
            .set('@api', resolve('api'))  
            .set('@store', resolve('store'))  
            .set('@components', resolve('components'))  
            .set('@utils', resolve('utils'));  
    },  
    css: {  
        loaderOptions: {  
            // 给 sass-loader 传递 Sass.js 相关选项  
            sass: {}  
        }  
    },  
    devServer: {  
        proxy: {  
            '/api': {  
                target: 'https://agile.szjfj.net',  
                secure: false,  
                changeOrigin: true,  
                pathRewrite: {  
                    '^/api': ''  
                }  
            }  
        }  
    }  
}  

// index.vue  
<style lang="scss" scoped>  
@import '@common/common.scss';  

.content {  
    h1 {  
        color: red;  
        background: $base-color;  
    }  
}  
</style>  

// main.js  
import api from '@api';  
import message from '@components/quick-message/quick-message.vue'

项目目录:见附件
报错:

Module build failed (from ./node_modules/sass-loader/dist/cjs.js):  
10:21:37.012 SassError: File to import not found or unreadable: @common/common.scss.  
10:21:37.017        Parent style sheet: F:\运维平台重构\可视化创建\pages\index\index.vue  
10:21:37.027         on line 111 of stdin  
10:21:37.027 >> @import '@common/common.scss';  
10:21:37.038    ^  
10:21:37.048 文件查找失败:'@api' at main.js:4  
10:21:37.057 文件查找失败:'@components/quick-message/quick-message.vue' at main.js:5
2021-04-16 10:23 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复