Path aliases for imports in WebStorm

前端 未结 10 1899
日久生厌
日久生厌 2020-12-02 05:31

I use webpack path aliases for ES6 module loading.

E.g. If I define an alias for utils instead of something like
import Foo from \".

10条回答
  •  一整个雨季
    2020-12-02 06:10

    For the record: in PHPSTORM, working with laravel mix, I managed to solve this by creating a webpack.config.js file separately like:

    const path = require('path')
    const webpack = require('webpack')
    
    module.exports = {
      ...
      resolve: {
        extensions: ['.js', '.json', '.vue'],
        alias: {
          '~': path.resolve(__dirname, './resources/assets/js')
        }
      },
      ...
    }
    

    And then importing it in the webpack.mix.js like:

    const config = require('./webpack.config')
    ...
    mix.webpackConfig(config)
    

    Make sure the webpack configuration file is pointed correctly in the configuration of the PhpStorm in: Settings > Languages & Frameworks > Javascript > Webpack

提交回复
热议问题