test02/node_modules/@vuepress/helper/lib/node/bundler/addCustomElement.js
罗佳鸿 6aa1ebe342
Some checks are pending
部署文档 / deploy-gh-pages (push) Waiting to run
first commit
2024-08-13 10:11:19 +08:00

43 lines
1.6 KiB
JavaScript

import { isString } from '../../shared/index.js';
import { getBundlerName } from './getBundlerName.js';
/**
* Add tags as customElement
*
* @param bundlerOptions VuePress Bundler config
* @param app VuePress Node App
* @param customElements tags recognized as custom element
*/
export const addCustomElement = (bundlerOptions, app, customElement) => {
const customElements = isString(customElement)
? [customElement]
: customElement;
const bundlerName = getBundlerName(app);
// for vite
if (bundlerName === 'vite') {
const viteBundlerConfig = bundlerOptions;
const { isCustomElement } = (((viteBundlerConfig.vuePluginOptions ??=
{}).template ??= {}).compilerOptions ??= {});
viteBundlerConfig.vuePluginOptions.template.compilerOptions.isCustomElement =
(tag) => {
if (customElements instanceof RegExp
? customElements.test(tag)
: customElements.includes(tag))
return true;
return isCustomElement?.(tag);
};
}
// for webpack
else if (bundlerName === 'webpack') {
const webpackBundlerConfig = bundlerOptions;
const { isCustomElement } = ((webpackBundlerConfig.vue ??=
{}).compilerOptions ??= {});
webpackBundlerConfig.vue.compilerOptions.isCustomElement = (tag) => {
if (customElements instanceof RegExp
? customElements.test(tag)
: customElements.includes(tag))
return true;
return isCustomElement?.(tag);
};
}
};