-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 48c4b7d
Showing
7 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# resolve-ts-aliases | ||
|
||
Resolve aliases for integrating webpack and typescript. | ||
|
||
## Install | ||
|
||
```bash | ||
npm add -D resolve-ts-aliases | ||
``` | ||
|
||
## Usage | ||
|
||
`tsconfig.json`: | ||
|
||
```json | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "./", | ||
"paths": { | ||
"@app/*": ["src/app/*"], | ||
"@components/*": ["src/components/*"] | ||
} | ||
} | ||
} | ||
``` | ||
|
||
`webpack.config.ts`: | ||
|
||
```ts | ||
import * as path from "path"; | ||
import * as webpack from "webpack"; | ||
import { resolveTsAliases } from "webpack-ts-utils"; | ||
|
||
const config: webpack.Configuration = { | ||
resolve: { | ||
// These 2 forms are equivalent. | ||
alias: resolveTsAliases(path.resolve("tsconfig.json")), | ||
alias: { | ||
"@app": "/path/to/src/app", | ||
"@components": "/path/to/src/components" | ||
} | ||
}, | ||
}; | ||
|
||
export default config; | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "resolve-ts-aliases", | ||
"version": "1.0.0", | ||
"description": "Resolve aliases for integrating webpack and typescript.", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "rm -rf dist && tsc", | ||
"prepare": "npm run build", | ||
"release": "npm publish --access public" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^12.7.4", | ||
"typescript": "^3.6.2" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/arzyu/resolve-ts-aliases" | ||
}, | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { resolve, dirname} from "path"; | ||
|
||
export const resolveTsAliases = (tsconfigPath: string) => { | ||
const { baseUrl, paths } = require(tsconfigPath).compilerOptions; | ||
const pathPrefix = resolve(dirname(tsconfigPath), baseUrl); | ||
const aliases: { [key: string]: string } = {}; | ||
|
||
Object.keys(paths).forEach((item) => { | ||
const name = item.replace("/*", ""); | ||
const value = resolve(pathPrefix, paths[item][0].replace("/*", "")); | ||
|
||
aliases[name] = value; | ||
}); | ||
|
||
return aliases; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"module": "commonjs", | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"declaration": true, | ||
"baseUrl": "./", | ||
"outDir": "./dist" | ||
}, | ||
"files": ["src/index.ts"] | ||
} |