mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-22 06:31:45 +08:00
perf(cli): simplify babel cache
This commit is contained in:
parent
4d86375ac6
commit
f4d10df14d
@ -76,7 +76,6 @@
|
|||||||
"cross-env": "^6.0.3",
|
"cross-env": "^6.0.3",
|
||||||
"css-loader": "^3.4.1",
|
"css-loader": "^3.4.1",
|
||||||
"eslint": "^6.8.0",
|
"eslint": "^6.8.0",
|
||||||
"find-babel-config": "^1.2.0",
|
|
||||||
"gh-pages": "2.0.1",
|
"gh-pages": "2.0.1",
|
||||||
"html-webpack-plugin": "3.2.0",
|
"html-webpack-plugin": "3.2.0",
|
||||||
"husky": "^4.0.4",
|
"husky": "^4.0.4",
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
const babelConfig = require('./lib/config/babel.config');
|
const babelConfig = require('./lib/config/babel.config');
|
||||||
|
|
||||||
module.exports = () => babelConfig();
|
module.exports = api => babelConfig(api);
|
||||||
|
@ -36,7 +36,7 @@ async function compileFile(filePath: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isScript(filePath)) {
|
if (isScript(filePath)) {
|
||||||
return compileJs(filePath, { reloadConfig: true });
|
return compileJs(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isStyle(filePath)) {
|
if (isStyle(filePath)) {
|
||||||
@ -153,7 +153,7 @@ async function buildPackageEntry() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
setModuleEnv('esmodule');
|
setModuleEnv('esmodule');
|
||||||
await compileJs(esEntryFile, { reloadConfig: true });
|
await compileJs(esEntryFile);
|
||||||
|
|
||||||
genPacakgeStyle({
|
genPacakgeStyle({
|
||||||
outputPath: styleEntryFile,
|
outputPath: styleEntryFile,
|
||||||
@ -162,7 +162,7 @@ async function buildPackageEntry() {
|
|||||||
|
|
||||||
setModuleEnv('commonjs');
|
setModuleEnv('commonjs');
|
||||||
await copy(esEntryFile, libEntryFile);
|
await copy(esEntryFile, libEntryFile);
|
||||||
await compileJs(libEntryFile, { reloadConfig: true });
|
await compileJs(libEntryFile);
|
||||||
await compileStyle(styleEntryFile);
|
await compileStyle(styleEntryFile);
|
||||||
|
|
||||||
stepper.success('Build Package Entry');
|
stepper.success('Build Package Entry');
|
||||||
|
@ -1,49 +1,11 @@
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import findBabelConfig from 'find-babel-config';
|
|
||||||
import { join } from 'path';
|
|
||||||
import { transformFileAsync } from '@babel/core';
|
import { transformFileAsync } from '@babel/core';
|
||||||
import { removeSync, outputFileSync, existsSync } from 'fs-extra';
|
import { removeSync, outputFileSync } from 'fs-extra';
|
||||||
import { replaceExt } from '../common';
|
import { replaceExt } from '../common';
|
||||||
import { ROOT, DIST_DIR } from '../common/constant';
|
|
||||||
|
|
||||||
type Options = {
|
export function compileJs(filePath: string): Promise<undefined> {
|
||||||
// whether to fouce reload babel config
|
|
||||||
reloadConfig?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
const TEMP_BABEL_CONFIG = join(DIST_DIR, 'babel.config.js');
|
|
||||||
|
|
||||||
function genTempBabelConfig() {
|
|
||||||
const { config } = findBabelConfig.sync(ROOT);
|
|
||||||
const content = `module.exports = function (api) {
|
|
||||||
api.cache.never();
|
|
||||||
|
|
||||||
return ${JSON.stringify(config)}
|
|
||||||
};`;
|
|
||||||
|
|
||||||
outputFileSync(TEMP_BABEL_CONFIG, content);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBabelOptions(options: Options) {
|
|
||||||
if (options.reloadConfig) {
|
|
||||||
if (!existsSync(TEMP_BABEL_CONFIG)) {
|
|
||||||
genTempBabelConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
configFile: TEMP_BABEL_CONFIG
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function compileJs(
|
|
||||||
filePath: string,
|
|
||||||
options: Options = {}
|
|
||||||
): Promise<undefined> {
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
transformFileAsync(filePath, getBabelOptions(options))
|
transformFileAsync(filePath)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result) {
|
if (result) {
|
||||||
const jsFilePath = replaceExt(filePath, '.js');
|
const jsFilePath = replaceExt(filePath, '.js');
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
module.exports = function() {
|
import { ConfigAPI } from '@babel/core';
|
||||||
|
|
||||||
|
module.exports = function(api?: ConfigAPI) {
|
||||||
|
if (api) {
|
||||||
|
api.cache.never();
|
||||||
|
}
|
||||||
|
|
||||||
const { BABEL_MODULE, NODE_ENV } = process.env;
|
const { BABEL_MODULE, NODE_ENV } = process.env;
|
||||||
const isTest = NODE_ENV === 'test';
|
const isTest = NODE_ENV === 'test';
|
||||||
const useESModules = BABEL_MODULE !== 'commonjs' && !isTest;
|
const useESModules = BABEL_MODULE !== 'commonjs' && !isTest;
|
||||||
|
@ -4921,14 +4921,6 @@ finalhandler@~1.1.2:
|
|||||||
statuses "~1.5.0"
|
statuses "~1.5.0"
|
||||||
unpipe "~1.0.0"
|
unpipe "~1.0.0"
|
||||||
|
|
||||||
find-babel-config@^1.2.0:
|
|
||||||
version "1.2.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/find-babel-config/-/find-babel-config-1.2.0.tgz#a9b7b317eb5b9860cda9d54740a8c8337a2283a2"
|
|
||||||
integrity sha512-jB2CHJeqy6a820ssiqwrKMeyC6nNdmrcgkKWJWmpoxpE8RKciYJXCcXRq1h2AzCo5I5BJeN2tkGEO3hLTuePRA==
|
|
||||||
dependencies:
|
|
||||||
json5 "^0.5.1"
|
|
||||||
path-exists "^3.0.0"
|
|
||||||
|
|
||||||
find-cache-dir@^2.0.0, find-cache-dir@^2.1.0:
|
find-cache-dir@^2.0.0, find-cache-dir@^2.1.0:
|
||||||
version "2.1.0"
|
version "2.1.0"
|
||||||
resolved "https://registry.npm.taobao.org/find-cache-dir/download/find-cache-dir-2.1.0.tgz?cache=0&sync_timestamp=1573277814677&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Ffind-cache-dir%2Fdownload%2Ffind-cache-dir-2.1.0.tgz#8d0f94cd13fe43c6c7c261a0d86115ca918c05f7"
|
resolved "https://registry.npm.taobao.org/find-cache-dir/download/find-cache-dir-2.1.0.tgz?cache=0&sync_timestamp=1573277814677&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Ffind-cache-dir%2Fdownload%2Ffind-cache-dir-2.1.0.tgz#8d0f94cd13fe43c6c7c261a0d86115ca918c05f7"
|
||||||
@ -6937,7 +6929,7 @@ json5@2.x, json5@^2.1.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
minimist "^1.2.0"
|
minimist "^1.2.0"
|
||||||
|
|
||||||
json5@^0.5.0, json5@^0.5.1:
|
json5@^0.5.0:
|
||||||
version "0.5.1"
|
version "0.5.1"
|
||||||
resolved "https://registry.npm.taobao.org/json5/download/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"
|
resolved "https://registry.npm.taobao.org/json5/download/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"
|
||||||
integrity sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=
|
integrity sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user