Skip to content

Add your own alias to packages so you don't have to type "../" a hundred times

License

Notifications You must be signed in to change notification settings

viniciussalvati/react-app-rewire-alias

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-app-rewire-alias

Add your own alias to packages so you don't have to type "../" a hundred times

NOT YET TESTED FOR PRODUCTION BUILDS

How this package works

Add the aliases to webpack's alias. If any starts with ~/, we will replace it by ./ and run it through path.resolve before adding it to webpack.

Usage

module.exports = require('react-app-rewire-alias')({
	alias: {
		'@app': '~/src',
		'@components': '~/src/components'
	}
});

// or

module.exports = function override(config, env) {

	//do stuff with the webpack config...
	const rewire = react_app_rewired.compose(
		//...
		require('react-app-rewire-alias')({
			alias: {
				'@app': '~/src',
				'@components': '~/src/components'
			}
		})
		//...
		),
	);

	return rewire(config, env);
};

For Typescript users

We usually have to configure our tsconfig.json so that alias can work, so we have an option to read the tsconfig.json file.

The following setup is equivalent to the one above.

tsconfig.json:

{
	"compilerOptions":{
		// other options
		"paths": {
			"@app/*": [
				"./src/*"
			],
			"@components/*": [
				"./src/components/*"
			]
		}
	}
}
module.exports = require('react-app-rewire-alias').fromTsConfig();

About

Add your own alias to packages so you don't have to type "../" a hundred times

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published