Skip to content

Commit

Permalink
fix: duplicated @
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 committed Jun 16, 2021
1 parent 4bcf18a commit 9d707db
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
25 changes: 11 additions & 14 deletions src/transform/transformVuecli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,17 @@ export class VueCliTransformer implements Transformer {
return (originConfig.resolve && originConfig.resolve.alias) || {};
}
})();
const finalAlias = [];
finalAlias.push({ find: new RawValue('/^~/'), replacement: ''});
finalAlias.push({
find: '@',
replacement: new RawValue('path.resolve(__dirname,\'src\')'),
});
const defaultAlias = {};
defaultAlias['/^~/'] = '';
defaultAlias['@'] = 'path.resolve(__dirname,\'src\')';
const alias = {
...defaultAlias,
...aliasOfConfigureWebpackObjectMode,
...aliasOfConfigureFunctionMode,
...aliasOfChainWebpack,
}
Object.keys(alias).forEach((key) => {
finalAlias.push({
find: key,
replacement: path.relative(process.cwd(), alias[key]),
});
});

config.resolve = {};
config.resolve.alias = finalAlias;
config.resolve.extensions = [
'.mjs',
'.js',
Expand All @@ -119,7 +110,13 @@ export class VueCliTransformer implements Transformer {
'.json',
'.vue',
];

config.resolve.alias = [];
Object.keys(alias).forEach((key) => {
config.resolve.alias.push({
find: key,
replacement: path.relative(process.cwd(), alias[key]),
});
});
config = removeUndefined(config);
return config;
}
Expand Down
27 changes: 16 additions & 11 deletions tests/testdata/vue.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
const path = require('path');
const path = require('path')

function resolve(dir) {
return path.join(__dirname, dir)
return path.join(__dirname, dir)
}

module.exports = {
baseUrl: '/src',
publicPath: process.env.NODE_ENV === 'production' ? '/' : '/',
configureWebpack: {
resolve: {
alias: {
'@components': resolve('./src/components'),
'assets': resolve('./src/assets/'),
}
}
baseUrl: '/src',
publicPath: process.env.NODE_ENV === 'production' ? '/' : '/',
configureWebpack: {
resolve: {
alias: {
'@components': resolve('./src/components'),
assets: resolve('./src/assets/')
}
}
},
chainWebpack: config => {
config.resolve.alias
.set('@', resolve('src')) // key,value自行定义,比如.set('@@', resolve('src/components'))
.set('_c', resolve('src/components'))
}
}

0 comments on commit 9d707db

Please sign in to comment.