refactor(@vant/cli): migrate to ESM package
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
import { ConfigAPI } from '@babel/core';
|
||||
|
||||
type PresetOption = {
|
||||
loose?: boolean;
|
||||
enableObjectSlots?: boolean;
|
||||
};
|
||||
|
||||
module.exports = function (api?: ConfigAPI, options: PresetOption = {}) {
|
||||
if (api) {
|
||||
api.cache.never();
|
||||
}
|
||||
|
||||
const { BABEL_MODULE, NODE_ENV } = process.env;
|
||||
const isTest = NODE_ENV === 'test';
|
||||
const useESModules = BABEL_MODULE !== 'commonjs' && !isTest;
|
||||
|
||||
return {
|
||||
presets: [
|
||||
[
|
||||
require.resolve('@babel/preset-env'),
|
||||
{
|
||||
modules: useESModules ? false : 'commonjs',
|
||||
loose: options.loose,
|
||||
},
|
||||
],
|
||||
require.resolve('@babel/preset-typescript'),
|
||||
require('../compiler/babel-preset-vue-ts'),
|
||||
],
|
||||
plugins: [
|
||||
[
|
||||
require.resolve('@vue/babel-plugin-jsx'),
|
||||
{
|
||||
enableObjectSlots: options.enableObjectSlots,
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
};
|
||||
|
||||
export default module.exports;
|
||||
@@ -1,47 +0,0 @@
|
||||
import { join } from 'path';
|
||||
import { existsSync } from 'fs-extra';
|
||||
import {
|
||||
ROOT,
|
||||
JEST_SETUP_FILE,
|
||||
JEST_FILE_MOCK_FILE,
|
||||
JEST_STYLE_MOCK_FILE,
|
||||
} from '../common/constant';
|
||||
|
||||
const DEFAULT_CONFIG = {
|
||||
testEnvironment: 'jsdom',
|
||||
moduleNameMapper: {
|
||||
'\\.(css|less|scss)$': JEST_STYLE_MOCK_FILE,
|
||||
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': JEST_FILE_MOCK_FILE,
|
||||
},
|
||||
setupFilesAfterEnv: [JEST_SETUP_FILE],
|
||||
moduleFileExtensions: ['js', 'jsx', 'vue', 'ts', 'tsx'],
|
||||
transform: {
|
||||
'\\.(vue)$': 'vue3-jest',
|
||||
'\\.(js|jsx|ts|tsx)$': 'babel-jest',
|
||||
},
|
||||
transformIgnorePatterns: ['/node_modules/(?!(@vant/cli))/'],
|
||||
snapshotSerializers: ['jest-serializer-html'],
|
||||
collectCoverage: true,
|
||||
collectCoverageFrom: [
|
||||
'src/**/*.{js,jsx,ts,tsx,vue}',
|
||||
'!**/demo/**',
|
||||
'!**/test/**',
|
||||
],
|
||||
coverageReporters: ['html', 'lcov', 'text-summary'],
|
||||
coverageDirectory: './test/coverage',
|
||||
};
|
||||
|
||||
function readRootConfig() {
|
||||
const ROOT_CONFIG_PATH = join(ROOT, 'jest.config.js');
|
||||
|
||||
if (existsSync(ROOT_CONFIG_PATH)) {
|
||||
return require(ROOT_CONFIG_PATH);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
...DEFAULT_CONFIG,
|
||||
...readRootConfig(),
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
module.exports = 'test-file-stub';
|
||||
@@ -1 +0,0 @@
|
||||
import 'jest-canvas-mock';
|
||||
@@ -1 +0,0 @@
|
||||
module.exports = {};
|
||||
@@ -1,43 +0,0 @@
|
||||
import { existsSync } from 'fs-extra';
|
||||
import { ROOT_POSTCSS_CONFIG_FILE } from '../common/constant';
|
||||
|
||||
type PostcssConfig = {
|
||||
plugins?: Record<string, unknown> | any[];
|
||||
};
|
||||
|
||||
export function getRootPostcssConfig(): PostcssConfig {
|
||||
if (existsSync(ROOT_POSTCSS_CONFIG_FILE)) {
|
||||
return require(ROOT_POSTCSS_CONFIG_FILE);
|
||||
}
|
||||
return { plugins: [] };
|
||||
}
|
||||
|
||||
function getPostcssPlugins(rootConfig: PostcssConfig) {
|
||||
const plugins = rootConfig.plugins || [];
|
||||
|
||||
if (Array.isArray(plugins)) {
|
||||
const hasPostcssPlugin = plugins.find(
|
||||
(plugin) =>
|
||||
plugin === 'autoprefixer' && plugin.postcssPlugin === 'autoprefixer'
|
||||
);
|
||||
if (hasPostcssPlugin) {
|
||||
return plugins;
|
||||
}
|
||||
return [require('autoprefixer'), ...plugins];
|
||||
}
|
||||
|
||||
return {
|
||||
autoprefixer: {},
|
||||
...plugins,
|
||||
};
|
||||
}
|
||||
|
||||
function resolvePostcssConfig() {
|
||||
const rootConfig = getRootPostcssConfig();
|
||||
return {
|
||||
...rootConfig,
|
||||
plugins: getPostcssPlugins(rootConfig),
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = resolvePostcssConfig();
|
||||
@@ -1,7 +1,7 @@
|
||||
import { join } from 'path';
|
||||
import type { InlineConfig } from 'vite';
|
||||
import { setBuildTarget } from '../common';
|
||||
import { CWD, ES_DIR, getVantConfig, LIB_DIR } from '../common/constant';
|
||||
import { setBuildTarget } from '../common/index.js';
|
||||
import { CWD, ES_DIR, getVantConfig, LIB_DIR } from '../common/constant.js';
|
||||
|
||||
export function getViteConfigForPackage(minify: boolean): InlineConfig {
|
||||
setBuildTarget('package');
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
import { join } from 'path';
|
||||
import { get } from 'lodash';
|
||||
import { get } from 'lodash-es';
|
||||
import { createRequire } from 'module';
|
||||
import hljs from 'highlight.js';
|
||||
import vitePluginMd from 'vite-plugin-md';
|
||||
import vitePluginVue from '@vitejs/plugin-vue';
|
||||
import vitePluginJsx from '@vitejs/plugin-vue-jsx';
|
||||
import { setBuildTarget, getVantConfig, isDev } from '../common';
|
||||
import { setBuildTarget, getVantConfig, isDev } from '../common/index.js';
|
||||
import {
|
||||
SITE_DIST_DIR,
|
||||
SITE_MOBILE_SHARED_FILE,
|
||||
SITE_DESKTOP_SHARED_FILE,
|
||||
SITE_SRC_DIR,
|
||||
} from '../common/constant';
|
||||
} from '../common/constant.js';
|
||||
import { injectHtml } from 'vite-plugin-html';
|
||||
import type { InlineConfig } from 'vite';
|
||||
import type MarkdownIt from 'markdown-it';
|
||||
@@ -43,10 +44,7 @@ function markdownCardWrapper(htmlCode: string) {
|
||||
|
||||
// add target="_blank" to all links
|
||||
function markdownLinkOpen(md: MarkdownIt) {
|
||||
const defaultRender =
|
||||
md.renderer.rules.link_open ||
|
||||
((tokens, idx, options, env, self) =>
|
||||
self.renderToken(tokens, idx, options));
|
||||
const defaultRender = md.renderer.rules.link_open;
|
||||
|
||||
md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
|
||||
const aIndex = tokens[idx].attrIndex('target');
|
||||
@@ -55,7 +53,11 @@ function markdownLinkOpen(md: MarkdownIt) {
|
||||
tokens[idx].attrPush(['target', '_blank']); // add new attribute
|
||||
}
|
||||
|
||||
return defaultRender(tokens, idx, options, env, self);
|
||||
if (defaultRender) {
|
||||
return defaultRender(tokens, idx, options, env, self);
|
||||
}
|
||||
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -117,6 +119,7 @@ export function getViteConfigForSiteDev(): InlineConfig {
|
||||
highlight: markdownHighlight,
|
||||
},
|
||||
markdownItSetup(md: MarkdownIt) {
|
||||
const require = createRequire(import.meta.url);
|
||||
const { slugify } = require('transliteration');
|
||||
const markdownItAnchor = require('markdown-it-anchor');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user