mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(cli): compile commonjs module
This commit is contained in:
parent
19ceb9dddb
commit
71415e467d
@ -73,6 +73,7 @@
|
|||||||
"csso": "^4.0.2",
|
"csso": "^4.0.2",
|
||||||
"decamelize": "^3.2.0",
|
"decamelize": "^3.2.0",
|
||||||
"eslint": "^6.7.1",
|
"eslint": "^6.7.1",
|
||||||
|
"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": "^3.1.0",
|
"husky": "^3.1.0",
|
||||||
|
@ -45,7 +45,7 @@ async function compileDir(dir: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isScript(filePath)) {
|
if (isScript(filePath)) {
|
||||||
return compileJs(filePath);
|
return compileJs(filePath, { reloadConfig: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isStyle(filePath)) {
|
if (isStyle(filePath)) {
|
||||||
@ -129,7 +129,7 @@ async function buildPackageEntry() {
|
|||||||
setModuleEnv('commonjs');
|
setModuleEnv('commonjs');
|
||||||
|
|
||||||
await copy(esEntryFile, libEntryFile);
|
await copy(esEntryFile, libEntryFile);
|
||||||
await compileJs(libEntryFile);
|
await compileJs(libEntryFile, { reloadConfig: true });
|
||||||
await compileStyle(styleEntryFile);
|
await compileStyle(styleEntryFile);
|
||||||
|
|
||||||
stepper.success('Build Package Entry');
|
stepper.success('Build Package Entry');
|
||||||
|
@ -1,10 +1,49 @@
|
|||||||
|
// @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 } from 'fs-extra';
|
import { removeSync, outputFileSync, existsSync } from 'fs-extra';
|
||||||
import { replaceExt } from '../common';
|
import { replaceExt } from '../common';
|
||||||
|
import { CWD, DIST_DIR } from '../common/constant';
|
||||||
|
|
||||||
export function compileJs(filePath: string): Promise<undefined> {
|
type Options = {
|
||||||
|
// whether to fouce reload babel config
|
||||||
|
reloadConfig?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const TEMP_BABEL_CONFIG = join(DIST_DIR, 'babel.config.js');
|
||||||
|
|
||||||
|
function genTempBabelConfig() {
|
||||||
|
const { config } = findBabelConfig.sync(CWD);
|
||||||
|
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)
|
transformFileAsync(filePath, getBabelOptions(options))
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result) {
|
if (result) {
|
||||||
const jsFilePath = replaceExt(filePath, '.js');
|
const jsFilePath = replaceExt(filePath, '.js');
|
||||||
|
@ -39,7 +39,7 @@ const version = '${version}';
|
|||||||
|
|
||||||
function install(Vue) {
|
function install(Vue) {
|
||||||
const components = [
|
const components = [
|
||||||
${components.filter(item => !skipInstall.includes(item)).join(',\n ')}
|
${components.filter(item => !skipInstall.includes(item)).join(',\n ')}
|
||||||
];
|
];
|
||||||
|
|
||||||
components.forEach(item => {
|
components.forEach(item => {
|
||||||
|
@ -4651,6 +4651,14 @@ 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"
|
||||||
@ -6560,7 +6568,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.0, json5@^0.5.1:
|
||||||
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