Skip to content

Instantly share code, notes, and snippets.

@tschoffelen
Last active September 27, 2018 09:21
Show Gist options
  • Save tschoffelen/33b3ee118f53e04a96a3d19eedc16107 to your computer and use it in GitHub Desktop.
Save tschoffelen/33b3ee118f53e04a96a3d19eedc16107 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