VueJS 2:本地资产 [英] VueJS 2: Local assets

查看:45
本文介绍了VueJS 2:本地资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 cli 创建了一个项目,并且在生成的资产文件夹中有一些 css 和 js 文件.我正在尝试将它们添加到 index.html 文件中,但它一直作为 404 返回.是否有其他方法需要添加我的本地 css 和 javascript 文件?

I made a project with the cli and I have some css and js files in the assets folder that was generated. I am trying to add them to the index.html file but it keeps coming back as a 404. Is there a different way I need to add my local css and javascript files?

推荐答案

在你的 webpack 配置文件中,你可以为你的 assets 文件夹添加一个别名:

In your webpack config file, you can add an alias for your assets folder:

module.exports = { 
  ...
  resolve: {
    alias: {
      'assets': path.resolve(__dirname, '../src/assets'),
    },
    ...
  },
  ...
},

然后,在您的应用程序中,您可以像这样引用此文件夹:

Then, in your application, you can reference this folder like so:

// in a .less file
@import "~assets/css/vars"

// in a .js file
require("assets/js/utils")

这篇关于VueJS 2:本地资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆