Use webpack.config provided by vue-cli

Hey there,

is there any chance to enable Webstorm to use the webpack.config.js provided by vue-cli? Since there is no webpack.config.js Webpack can't resolve relative SASS imports like @import '~/styles/fonts.scss' and is showing error messages.

0
11 comments

For Vue-cli 3.x, you have to specify node_modules/@vue/cli-service/webpack.config.js. as Preferences | Languages & Frameworks | JavaScript | Webpack

3
Avatar
Permanently deleted user

Well, seems to be pretty straight forward. Anyways will WebStorm be able to resolve custom configuration through a modified Vue-CLI config?

0

Not sure; it depends on a way you modify it, etc.

0
Avatar
Permanently deleted user
For Vue-cli 3.x, you have to specify node_modules/@vue/cli-service/webpack.config.js. as Preferences | Languages & Frameworks | JavaScript | Webpack

 

Just want to expand on this answer, by marking my src folder as resource route worked for me...

PS: mark your root folder after adding the path to webpack config otherwise it wont work

1

You normally don't need marking any folders in a special way to make this work...

What IDE version do you work with? Can you share a sample project that shows up the issue? Is it JavaScript or TypeScript project?

0
Avatar
Permanently deleted user

@Elena: setting the 

node_modules/@vue/cli-service/webpack.config.js. under File > Settings... > Languages & Frameworks > JavaScript > Webpack

does not work for me.

The only way to get aliases to work is creating a webpack.config.js file that has the alias defined in it or marking the src directory as resource root.

module.exports = {
  resolve: {
    alias: {
      "@": require("path").resolve(__dirname, "src")
    }
  }
};

I'm running Webstorm version 2018.3.

Any idea why this isn't working for me?

0

No idea, sorry. Can you share a project that shows up the issue plus your idea.log?

0

Specified this path in Languages & Frameworks > JavaScript > Webpack worked for me 🎉

/Users/<path-to-project>/node_modules/@vue/cli-service/webpack.config.js
0

How to do that in a multi-module project with no global node_modules directory? Is it okay to have a webpack.config.js in the root project that has no other purpose than telling the IDE where the source directories are? (Althoug this would mean I could reference components from other modules that may not be available in the current)

0

>Is it okay to have a webpack.config.js in the root project that has no other purpose than telling the IDE where the source directories are? 

yes, dummy config is a good solution; but note that all paths specified there should be valid, they have to be resolved during evaluation, the aliases, etc. won't work otherwise

0

I was able to fix my issue with a `jsconfig.json` file in my projects directory.

{
"allowJs": true,
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["src/**/*", "tests/**/*"],
"exclude": ["node_modules"]
}
3

Please sign in to leave a comment.