Skip to content

Instantly share code, notes, and snippets.

@suhanlee
Forked from tschoffelen/webpack.config.js
Created May 6, 2018 21:19
Show Gist options
  • Save suhanlee/98f90fc2f152a4e8cee3f2e056b49281 to your computer and use it in GitHub Desktop.
Save suhanlee/98f90fc2f152a4e8cee3f2e056b49281 to your computer and use it in GitHub Desktop.
Tricking PHPStorm in supporting React Native path aliases.
/**
* Why is this here you ask? React Native doesn't use Webpack. True. This file is here to trick
* IDEA in recognizing module aliases (see the package.json files in some of the subdirs).
* Nice solution? No. Does it work? Sure.
* Tracker URL: https://youtrack.jetbrains.com/issue/WEB-23221
*
* - TS
*/
const fs = require('fs')
const path = require('path')
const walkSync = function (dir, filelist) {
const files = fs.readdirSync(dir)
filelist = filelist || []
files.forEach(function (file) {
if (fs.statSync(dir + file).isDirectory()) {
filelist = walkSync(dir + file + '/', filelist)
} else if (file === 'package.json') {
filelist.push([path.resolve(dir), path.resolve(dir + file)])
}
})
return filelist
}
const alias = {}
walkSync('src/').forEach((p) => {
const pkg = require(p[1])
alias[pkg.name] = p[0]
})
module.exports = {
resolve: {
alias
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment