UNPKG

@umijs/plugins

Version:
98 lines (96 loc) 3.55 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/styled-components.ts var styled_components_exports = {}; __export(styled_components_exports, { default: () => styled_components_default }); module.exports = __toCommonJS(styled_components_exports); var import_utils = require("@umijs/utils"); var import_path = require("path"); var import_withTmpPath = require("./utils/withTmpPath"); var styled_components_default = (api) => { api.describe({ key: "styledComponents", config: { schema({ zod }) { return zod.object({ babelPlugin: zod.record(zod.any()).optional() }); } }, enableBy: api.EnableBy.config }); api.modifyBabelPresetOpts((memo) => { if (api.env === "development") { memo.pluginStyledComponents = { ...api.config.styledComponents.babelPlugin }; } return memo; }); api.addRuntimePlugin(() => { return [(0, import_withTmpPath.withTmpPath)({ api, path: "runtime.tsx" })]; }); api.addRuntimePluginKey(() => { return ["styledComponents"]; }); const libPath = (0, import_path.dirname)(require.resolve("styled-components/package")); api.onGenerateFiles(() => { var _a; api.writeTmpFile({ path: "index.tsx", content: ` import styled, { ThemeProvider, createGlobalStyle, css, keyframes, StyleSheetManager, useTheme } from '${(0, import_utils.winPath)( libPath )}'; export { styled, ThemeProvider, createGlobalStyle, css, keyframes, StyleSheetManager, useTheme }; ` }); const styledComponentsRuntimeCode = ((_a = api.appData.appJS) == null ? void 0 : _a.exports.includes( "styledComponents" )) ? `import { styledComponents as styledComponentsConfig } from '@/app';` : `const styledComponentsConfig = {};`; api.writeTmpFile({ path: "runtime.tsx", content: ` ${styledComponentsRuntimeCode} export function rootContainer(container) { const globalStyle = styledComponentsConfig.GlobalStyle ? <styledComponentsConfig.GlobalStyle /> : null; return ( <> {globalStyle} {container} </> ); } ` }); }); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = {});