mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(cli): resolve npm mobules when compile less
This commit is contained in:
parent
8641b8b256
commit
b3993dd653
packages/vant-cli
src/icon
@ -30,7 +30,6 @@
|
|||||||
"@types/eslint": "^6.1.3",
|
"@types/eslint": "^6.1.3",
|
||||||
"@types/fs-extra": "^8.0.1",
|
"@types/fs-extra": "^8.0.1",
|
||||||
"@types/html-webpack-plugin": "^3.2.1",
|
"@types/html-webpack-plugin": "^3.2.1",
|
||||||
"@types/less": "^3.0.1",
|
|
||||||
"@types/lodash": "^4.14.149",
|
"@types/lodash": "^4.14.149",
|
||||||
"@types/postcss-load-config": "^2.0.1",
|
"@types/postcss-load-config": "^2.0.1",
|
||||||
"@types/sass": "^1.16.0",
|
"@types/sass": "^1.16.0",
|
||||||
|
@ -1,10 +1,26 @@
|
|||||||
|
// @ts-ignore
|
||||||
|
import { render, FileManager } from 'less';
|
||||||
import { readFileSync } from 'fs-extra';
|
import { readFileSync } from 'fs-extra';
|
||||||
import { render as renderLess } from 'less';
|
|
||||||
|
// less plugin to resolve tilde
|
||||||
|
class TildeResolver extends FileManager {
|
||||||
|
loadFile(filename: string, ...args: any[]) {
|
||||||
|
filename = filename.replace('~', '');
|
||||||
|
return FileManager.prototype.loadFile.apply(this, [filename, ...args]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const TildeResolverPlugin = {
|
||||||
|
install(lessInstance: unknown, pluginManager: any) {
|
||||||
|
pluginManager.addFileManager(new TildeResolver());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export async function compileLess(filePath: string) {
|
export async function compileLess(filePath: string) {
|
||||||
const source = readFileSync(filePath, 'utf-8');
|
const source = readFileSync(filePath, 'utf-8');
|
||||||
const { css } = await renderLess(source, {
|
const { css } = await render(source, {
|
||||||
filename: filePath
|
filename: filePath,
|
||||||
|
plugins: [TildeResolverPlugin]
|
||||||
});
|
});
|
||||||
|
|
||||||
return css;
|
return css;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { renderSync as renderSass } from 'sass';
|
import { renderSync } from 'sass';
|
||||||
|
|
||||||
export async function compileSass(filePath: string) {
|
export async function compileSass(filePath: string) {
|
||||||
const { css } = renderSass({ file: filePath });
|
const { css } = renderSync({ file: filePath });
|
||||||
return css;
|
return css;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import FriendlyErrorsPlugin from '@nuxt/friendly-errors-webpack-plugin';
|
import FriendlyErrorsPlugin from '@nuxt/friendly-errors-webpack-plugin';
|
||||||
import sass from 'sass';
|
import sass from 'sass';
|
||||||
import { resolve } from 'path';
|
|
||||||
import { VueLoaderPlugin } from 'vue-loader';
|
import { VueLoaderPlugin } from 'vue-loader';
|
||||||
import {
|
import {
|
||||||
ROOT,
|
|
||||||
STYLE_EXTS,
|
STYLE_EXTS,
|
||||||
SCRIPT_EXTS,
|
SCRIPT_EXTS,
|
||||||
POSTCSS_CONFIG_FILE
|
POSTCSS_CONFIG_FILE
|
||||||
@ -61,10 +59,7 @@ export const baseConfig = {
|
|||||||
use: [
|
use: [
|
||||||
...CSS_LOADERS,
|
...CSS_LOADERS,
|
||||||
{
|
{
|
||||||
loader: 'less-loader',
|
loader: 'less-loader'
|
||||||
options: {
|
|
||||||
paths: [resolve(ROOT, 'node_modules')]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -1386,11 +1386,6 @@
|
|||||||
resolved "https://registry.npm.taobao.org/@types/json-schema/download/@types/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
|
resolved "https://registry.npm.taobao.org/@types/json-schema/download/@types/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
|
||||||
integrity sha1-vf1p1h5GTcyBslFZwnDXWnPBpjY=
|
integrity sha1-vf1p1h5GTcyBslFZwnDXWnPBpjY=
|
||||||
|
|
||||||
"@types/less@^3.0.1":
|
|
||||||
version "3.0.1"
|
|
||||||
resolved "https://registry.npm.taobao.org/@types/less/download/@types/less-3.0.1.tgz#625694093c72f8356c4042754e222407e50d6b08"
|
|
||||||
integrity sha1-YlaUCTxy+DVsQEJ1TiIkB+UNawg=
|
|
||||||
|
|
||||||
"@types/lodash@^4.14.149":
|
"@types/lodash@^4.14.149":
|
||||||
version "4.14.149"
|
version "4.14.149"
|
||||||
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.149.tgz#1342d63d948c6062838fbf961012f74d4e638440"
|
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.149.tgz#1342d63d948c6062838fbf961012f74d4e638440"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
@import '../style/var';
|
@import '../style/var';
|
||||||
@import '@vant/icons/src/index.less';
|
@import '~@vant/icons/src/index.less';
|
||||||
|
|
||||||
.van-icon {
|
.van-icon {
|
||||||
&__image {
|
&__image {
|
||||||
|
@ -1 +1 @@
|
|||||||
@import '@vant/icons/src/encode.less';
|
@import '~@vant/icons/src/encode.less';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user