Skip to content
This repository has been archived by the owner on Jul 16, 2022. It is now read-only.

Commit

Permalink
fix(vue): Add support for alias in sassMixinsPath
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Nov 6, 2018
1 parent 76fe59b commit 799cb9a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
37 changes: 29 additions & 8 deletions packages/cli-plugin-vue/src/webpack/build.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
/* eslint-disable global-require,prefer-destructuring */
const path = require('path');
const fs = require('fs-extra');
const { info, chalk } = require('@vue/cli-shared-utils');
const resetWebpackConfig = require('./reset');
const buildWebpackEntries = require('./entries');
const buildWebpackAlias = require('./alias');
const buildWebpackAssets = require('./assets');

module.exports = (config, baseVueConfig) => {
const { scssMixinsPath, outputDir = config.currentWebsiteDir } = config.vueCli;
let sass = {};

if (fs.existsSync(scssMixinsPath)) {
sass = {
data: fs.readFileSync(scssMixinsPath, 'utf-8'),
includePaths: [path.dirname(scssMixinsPath)]
};
const { scssMixinsPath, scssMixins = [], outputDir = config.currentWebsiteDir, alias } = config.vueCli;
const isProd = process.env.NODE_ENV === 'production';

let sass = [scssMixinsPath]
.concat(scssMixins)
.filter(mixinsPath => !!mixinsPath && fs.existsSync(scssMixinsPath))
.reduce(
(acc, mixinsPath) => {
acc.data += `\n${fs.readFileSync(mixinsPath, 'utf-8')}`;
acc.includePaths.push(path.dirname(mixinsPath));

if (!isProd) {
info(`Add sass mixins: '${chalk.cyan(mixinsPath)}'`);
}

return acc;
},
{ data: '', includePaths: [] }
);

if (sass.includePaths.length === 0) {
sass = {};
} else {
Object.keys(alias).forEach(key => {
const search = new RegExp(key.replace(/@/, '~'), 'gi');
info(search.toString());
sass.data = sass.data.replace(search, alias[key]);
});
}

let baseUrl;
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ module.exports = (rootDir, contextDir) => [
{
name: 'parent:value',
pattern: /<([a-zA-Z\\-]*):(\w*)>/g,
replacement: nconf => (matched, storeName, value) => nconf.stores[storeName].get(value)
replacement: nconf => (matched, storeName, value) => nconf.stores[storeName].get(value.replace(/__/gi, ':'))
}
];

0 comments on commit 799cb9a

Please sign in to comment.