Skip to content

Commit

Permalink
fix: relative path cause alias uncorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 committed Jul 5, 2021
1 parent 220fed5 commit c18e94e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"dependencies": {
"chalk": "^4.1.1",
"@originjs/vue-sfc-ast-parser": "^1.0.0-beta0",
"chalk": "^4.1.1",
"commander": "^7.2.0",
"ejs": "^3.1.6",
"jscodeshift": "^0.12.0",
Expand Down
3 changes: 2 additions & 1 deletion src/transform/transformVuecli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export class VueCliTransformer implements Transformer {
...aliasOfChainWebpack
}
Object.keys(alias).forEach((key) => {
const relativePath = path.relative(rootDir, alias[key]).replace(/\\/g, '/')
let relativePath = path.relative(rootDir, path.resolve(rootDir, alias[key]))
relativePath = relativePath.replace(/\\/g, '/')
defaultAlias.push({
find: key,
replacement: new RawValue(`path.resolve(__dirname,'${relativePath}')`)
Expand Down
10 changes: 8 additions & 2 deletions src/transform/transformWebpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@ export class WebpackTransformer implements Transformer {

// convert alias
const defaultAlias = []

const alias = {
'@': `${rootDir}/src`
}
if (webpackConfig.resolve?.alias !== undefined) {
Object.keys(webpackConfig.resolve.alias).forEach((key) => {
alias[key] = webpackConfig.resolve.alias[key]
})
}

Object.keys(alias).forEach((key) => {
const relativePath = path.relative(rootDir, alias[key]).replace(/\\/g, '/')
let relativePath = path.relative(rootDir, path.resolve(rootDir, alias[key]))
relativePath = relativePath.replace(/\\/g, '/')
defaultAlias.push({
find: key,
replacement: new RawValue(`path.resolve(__dirname,'${relativePath}')`)
Expand Down

0 comments on commit c18e94e

Please sign in to comment.