typescript-paths-to-alias-plugin
v1.0.0
Published
Used to replace 'resolve.alias' of 'webpack' with 'paths' of 'typescript'
Downloads
2
Readme
typescript-paths-to-alias-plugin
Used to replace resolve.alias
of webpack.config.jS
with paths
of tsconfig.json
Install
npm install -D typescript-paths-to-alias-plugin
Example
tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"/*":["./*"],
"@*": ["./src/*","./src/*/index"]
}
}
The resolve.alias
of webpack
will become
{
'/': [ 'F:\\desktop\\react\\s' ],
'@': [ 'F:\\desktop\\react\\s\\src' ],
'@assets': [ 'F:\\desktop\\react\\s\\src\\assets' ],
'@utils': [ 'F:\\desktop\\react\\s\\src\\utils' ],
'@views': [ 'F:\\desktop\\react\\s\\src\\views' ]
}
Usage
webpack.config.js
const pathsToAlias = require('typescript-paths-to-alias-plugin')
module.exports = {
// ...
plugins: [new pathsToAlias({ aliasLog: true })]
}
or
const pathsToAlias = require('typescript-paths-to-alias-plugin')
module.exports = {
// ...
resolve:{
alias: pathsToAlias.getAlias()
}
}
Options
aliasLog
: Boolean- Show the replacement in your shell
defaule
: false