refactor(@vant/cli): migrate to ESM package

This commit is contained in:
chenjiahan
2021-10-28 20:09:00 +08:00
committed by neverland
parent eec2ac4c0f
commit 1b45f38133
50 changed files with 255 additions and 196 deletions
@@ -2,19 +2,21 @@
* Build style entry of all components
*/
import fse from 'fs-extra';
import { createRequire } from 'module';
import { sep, join, relative } from 'path';
import { outputFileSync } from 'fs-extra';
import { getComponents, replaceExt } from '../common';
import { CSS_LANG, getCssBaseFile } from '../common/css';
import { checkStyleExists } from './gen-style-deps-map';
import { getComponents, replaceExt } from '../common/index.js';
import { CSS_LANG, getCssBaseFile } from '../common/css.js';
import { checkStyleExists } from './gen-style-deps-map.js';
import {
ES_DIR,
SRC_DIR,
LIB_DIR,
STYLE_DEPS_JSON_FILE,
} from '../common/constant';
} from '../common/constant.js';
function getDeps(component: string): string[] {
const require = createRequire(import.meta.url);
const styleDepsJson = require(STYLE_DEPS_JSON_FILE);
if (styleDepsJson.map[component]) {
@@ -73,7 +75,7 @@ function genEntry(params: {
content += depsPath.map(template).join('\n');
content = content.replace(new RegExp('\\' + sep, 'g'), '/');
outputFileSync(outputFile, content);
fse.outputFileSync(outputFile, content);
});
}
@@ -81,6 +83,7 @@ export function genComponentStyle(
options: { cache: boolean } = { cache: true }
) {
if (!options.cache) {
const require = createRequire(import.meta.url);
delete require.cache[STYLE_DEPS_JSON_FILE];
}