VueJS 2: Local assets

2019-09-19 18:50发布

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?

标签: vuejs2
2条回答
女痞
2楼-- · 2019-09-19 19:31

Assuming you're using the webpack template, try /src/assets/... in the index.html

查看更多
聊天终结者
3楼-- · 2019-09-19 19:45

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")
查看更多
登录 后发表回答