mirror of
https://github.com/youzan/vant.git
synced 2025-10-20 18:54:24 +00:00
fix(cli): resolve npm mobules when compile less
This commit is contained in:
@@ -1,10 +1,26 @@
|
||||
// @ts-ignore
|
||||
import { render, FileManager } from 'less';
|
||||
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) {
|
||||
const source = readFileSync(filePath, 'utf-8');
|
||||
const { css } = await renderLess(source, {
|
||||
filename: filePath
|
||||
const { css } = await render(source, {
|
||||
filename: filePath,
|
||||
plugins: [TildeResolverPlugin]
|
||||
});
|
||||
|
||||
return css;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { renderSync as renderSass } from 'sass';
|
||||
import { renderSync } from 'sass';
|
||||
|
||||
export async function compileSass(filePath: string) {
|
||||
const { css } = renderSass({ file: filePath });
|
||||
const { css } = renderSync({ file: filePath });
|
||||
return css;
|
||||
}
|
||||
|
@@ -1,10 +1,8 @@
|
||||
// @ts-ignore
|
||||
import FriendlyErrorsPlugin from '@nuxt/friendly-errors-webpack-plugin';
|
||||
import sass from 'sass';
|
||||
import { resolve } from 'path';
|
||||
import { VueLoaderPlugin } from 'vue-loader';
|
||||
import {
|
||||
ROOT,
|
||||
STYLE_EXTS,
|
||||
SCRIPT_EXTS,
|
||||
POSTCSS_CONFIG_FILE
|
||||
@@ -61,10 +59,7 @@ export const baseConfig = {
|
||||
use: [
|
||||
...CSS_LOADERS,
|
||||
{
|
||||
loader: 'less-loader',
|
||||
options: {
|
||||
paths: [resolve(ROOT, 'node_modules')]
|
||||
}
|
||||
loader: 'less-loader'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
Reference in New Issue
Block a user