Vue-cli: Add './src' as a default resolve path

Created on 20 Mar 2018  路  1Comment  路  Source: vuejs/vue-cli

What problem does this feature solve?

As the app grows, managing the dependencies should be as simple and consistent as possible.
With complexity and multiple folders it can be tedious to travers through all the paths using relative references.

import Bar from '../../components/foo/Bar'
// Better
import Bar from 'components/foo/Bar'
````

This is super simple to do in Webpack.
Currently I create a config file looking like this:

```js
module.exports = {
  chainWebpack: config => {
    config.resolve.modules.add("./src");
  }
};

What does the proposed API look like?

Adding ./src to the default webpack config would make this easier for many people and prevent some errors for some developers as the path can always be used from the actual src folder.

Most helpful comment

You can already write:

import Bar from '@/components/foo/Bar'

IMHO this is even better because it's more explicit that it's from the source code and not from a node_modules package.

>All comments

You can already write:

import Bar from '@/components/foo/Bar'

IMHO this is even better because it's more explicit that it's from the source code and not from a node_modules package.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joshuajohnson814 picture joshuajohnson814  路  3Comments

OmgImAlexis picture OmgImAlexis  路  3Comments

miyamoto-san picture miyamoto-san  路  3Comments

NathanKleekamp picture NathanKleekamp  路  3Comments

eladcandroid picture eladcandroid  路  3Comments