UNPKG

@refly/arco-vite-plugin-react

Version:

For Vite build, load Arco Design styles on demand

49 lines 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.modifyIconConfig = exports.loadIcon = void 0; const config_1 = require("./config"); const utils_1 = require("./utils"); const filter = new RegExp(`(${config_1.iconCjsListMatchers[0]})|(${config_1.iconComponentMatchers[0]})`); function loadIcon(id, iconBox, iconBoxLib) { if (!iconBox || !iconBoxLib) { return; } // cjs -> es if ((0, utils_1.pathMatch)(id, config_1.iconCjsListMatchers)) { return `export * from './index.es.js'`; } const componentName = (0, utils_1.pathMatch)(id, config_1.iconComponentMatchers); if (componentName && iconBoxLib[componentName]) { return `export { default } from '${iconBox}/esm/${componentName}/index.js'`; } } exports.loadIcon = loadIcon; function modifyIconConfig(config, iconBox, iconBoxLib) { if (!iconBox || !iconBoxLib) { return; } // Pre-Bundling config.optimizeDeps = config.optimizeDeps || {}; config.optimizeDeps.esbuildOptions = config.optimizeDeps.esbuildOptions || {}; config.optimizeDeps.esbuildOptions.plugins = config.optimizeDeps.esbuildOptions.plugins || []; config.optimizeDeps.esbuildOptions.plugins.push({ name: 'arcoIconReplace', setup(build) { build.onLoad({ namespace: 'file', filter, }, ({ path: id }) => { const contents = loadIcon(id, iconBox, iconBoxLib); if (contents) { return { contents, loader: 'js', }; } return null; }); }, }); } exports.modifyIconConfig = modifyIconConfig; //# sourceMappingURL=icon.js.map