There is a lot of discussion here about Laravel Mix, so I'll leave this here to help out future readers. I solved this by creating a separate (fake) webpack config file which is only used by my IDE (PHPStorm).
1. Create a separate alias.js
file (e.g. /webpack/alias.js)
const path = require('path');
const assets = path.join(__dirname,'..','resources','assets');
module.exports = {
'@js' : path.resolve(assets, 'js'),
'@c' : path.resolve(assets, 'js', 'components'),
'@errors' : path.resolve(assets, 'js', 'errors'),
'@utils' : path.resolve(assets, 'js', 'utils'),
'@store' : path.resolve(assets, 'js', 'store'),
'@api' : path.resolve(assets, 'js', 'api'),
'@less' : path.resolve(assets, 'less')
}
2. Require the alias.js
file into webpack.mix.js
const mix = require('laravel-mix');
mix.alias(require('./webpack/alias'))
// ... The rest of your mix, e.g.
.js('app.js')
.vue()
.less('app.less');
3. Create the fake webpack config for your IDE (e.g. /webpack/ide.config.js)
Here, import the laravel-mix webpack config, plus your aliases, and any other config that the IDE might need help finding. Also include the prefixed ~ aliases for importing styles into your Vue components.
/*
|--------------------------------------------------------------------------
| A fake config file for PhpStorm to enable aliases
|--------------------------------------------------------------------------
|
| File > Settings... > Languages & Frameworks > Javascript > Webpack
|
| Select "Manually" and set the configuration file to this
|
*/
const path = require('path');
const mixConfig = require('./../node_modules/laravel-mix/setup/webpack.config')();
module.exports = {
...mixConfig,
resolve: {
alias: {
...require('./alias'),
'~@less' : path.resolve('@less'), // <--
},
...mixConfig.resolve
}
}
4. Set your IDE to use webpack/ide.config.js
as your webpack config file.