'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const chalk = require('chalk'); const msw = require('msw'); const globby = require('globby'); const ora = require('ora'); const nodeFetch = require('node-fetch'); const fsExtra = require('fs-extra'); const rimraf = require('rimraf'); const mockjs = require('mockjs'); const vite = require('vite'); const path = require('node:path'); const dts = require('vite-plugin-dts'); const bundleVisualizer = require('rollup-plugin-visualizer'); const pluginReact = require('@vitejs/plugin-react'); const vitePluginInspect = require('vite-plugin-inspect'); const vitePluginMock = require('vite-plugin-mock'); const viteTsconfigPaths = require('vite-tsconfig-paths'); const vitePluginSvgr = require('vite-plugin-svgr'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; } function _interopNamespace(e) { if (e && e.__esModule) return e; const n = Object.create(null); if (e) { for (const k in e) { n[k] = e[k]; } } n["default"] = e; return n; } const chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk); const msw__namespace = /*#__PURE__*/_interopNamespace(msw); const globby__namespace = /*#__PURE__*/_interopNamespace(globby); const ora__namespace = /*#__PURE__*/_interopNamespace(ora); const nodeFetch__namespace = /*#__PURE__*/_interopNamespace(nodeFetch); const fsExtra__namespace = /*#__PURE__*/_interopNamespace(fsExtra); const rimraf__default = /*#__PURE__*/_interopDefaultLegacy(rimraf); const rimraf__namespace = /*#__PURE__*/_interopNamespace(rimraf); const mockjs__namespace = /*#__PURE__*/_interopNamespace(mockjs); const path__default = /*#__PURE__*/_interopDefaultLegacy(path); const dts__default = /*#__PURE__*/_interopDefaultLegacy(dts); const bundleVisualizer__default = /*#__PURE__*/_interopDefaultLegacy(bundleVisualizer); const pluginReact__namespace = /*#__PURE__*/_interopNamespace(pluginReact); const vitePluginInspect__namespace = /*#__PURE__*/_interopNamespace(vitePluginInspect); const vitePluginMock__namespace = /*#__PURE__*/_interopNamespace(vitePluginMock); const viteTsconfigPaths__namespace = /*#__PURE__*/_interopNamespace(viteTsconfigPaths); const vitePluginSvgr__namespace = /*#__PURE__*/_interopNamespace(vitePluginSvgr); const WATCH = Boolean(process.env.WATCH); const REPORT = Boolean(process.env.REPORT); function changeViteConfig(config, options) { const { genDts = false, watch = false, dtsOptions, packagePath, report = false, reportOptions } = options; const pathResolve = (..._path) => path__default.resolve(packagePath, ..._path); if (!config.build) config.build = {}; if (!config.build.rollupOptions) config.build.rollupOptions = {}; if (!config.build.rollupOptions.plugins) config.build.rollupOptions.plugins = []; if (!config.plugins) config.plugins = []; config.build.emptyOutDir = false; if (genDts) { config.plugins.push( dts__default({ insertTypesEntry: true, tsConfigFilePath: pathResolve("./tsconfig.json"), ...dtsOptions }) ); } if (report) { config.build.rollupOptions.plugins.push( bundleVisualizer__default((outputOptions) => { return { open: true, filename: path__default.join(outputOptions.dir ?? "", "stats.html"), ...reportOptions?.(outputOptions) }; }) ); } if (watch) { config.build.watch = { include: pathResolve("./src/**/*") }; } return { ...config, configFile: false }; } async function build(config) { const { minifyConfig, unMinifyConfig, packagePath, changeConfigFn = changeViteConfig, dtsOptions, reportOptions } = config; const pathResolve = (..._path) => path__default.resolve(packagePath, ..._path); rimraf__default.sync(pathResolve("./dist/**/*")); if (!WATCH) { await vite.build(await changeConfigFn(minifyConfig, { packagePath, dtsOptions, report: REPORT, reportOptions })); } await vite.build( await changeConfigFn(unMinifyConfig, { genDts: true, watch: WATCH, packagePath, dtsOptions }) ); } const pascalCase = (str) => str.split("-").map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(""); const getOutputIndexName = (minify) => minify ? "index.min" : "index"; const getOutputMap = (minify) => ({ es: `${getOutputIndexName(minify)}.mjs`, cjs: `${getOutputIndexName(minify)}.cjs`, umd: `${getOutputIndexName(minify)}.umd.js`, iife: `${getOutputIndexName(minify)}.iife.js` }); const createViteConfig = (options) => { const { minify = false, packagePath, formats = ["es", "cjs", "umd", "iife"], externalMap = {}, dedupe: _dedupe = [], plugins = [], alias: _alias = [], test } = options; const outputMap = Object.fromEntries( Object.entries(getOutputMap(minify)).filter(([format]) => formats.includes(format)) ); const pathResolve = (..._path) => path__default.resolve(packagePath, ..._path); const pkg = require(pathResolve("./package.json")); const getPkgName = () => pkg.name; const dedupe = [ "vue", "vue-demi", "@vue/runtime-core", "@vue/runtime-dom", "vue2", "@vue/composition-api", ..._dedupe ]; const alias = [ ..._alias, { find: /@(?=\/)/, replacement: pathResolve("src") }, { find: /^@test/, replacement: pathResolve("test") } ]; return { root: pathResolve("./"), plugins, resolve: { dedupe, alias }, optimizeDeps: { exclude: ["vue-demi"] }, css: { postcss: { plugins: [require("autoprefixer"), require("cssnano")] }, preprocessorOptions: { less: { javascriptEnabled: true, rewriteUrls: "all" } } }, build: { outDir: pathResolve("dist"), lib: { entry: pathResolve("src/index.ts"), name: pascalCase(getPkgName().split("/").pop()), formats: Object.keys(outputMap), fileName: (format) => outputMap[format] }, rollupOptions: { output: { globals: externalMap, chunkFileNames: () => { return "[format]/[name].[format].js"; } }, external: Object.keys(externalMap) }, sourcemap: true, minify }, test: { globals: true, environment: "jsdom", setupFiles: [pathResolve("./test/setup.ts")], reporters: "dot", deps: { inline: ["vue", "vue2", "vue-demi", "@vue/composition-api"] }, ...test } }; }; const index = { __proto__: null, WATCH: WATCH, REPORT: REPORT, changeViteConfig: changeViteConfig, build: build, pascalCase: pascalCase, getOutputMap: getOutputMap, createViteConfig: createViteConfig }; exports.chalk = chalk__default; exports.msw = msw__namespace; exports.globby = globby__namespace; exports.ora = ora__namespace; exports.nodeFetch = nodeFetch__namespace; exports.fsExtra = fsExtra__namespace; exports.rimraf = rimraf__namespace; exports.mock = mockjs__namespace; exports.viteReact = pluginReact__namespace; exports.viteInspect = vitePluginInspect__namespace; exports.viteMock = vitePluginMock__namespace; exports.viteTsconfigPaths = viteTsconfigPaths__namespace; exports.viteSvgr = vitePluginSvgr__namespace; exports.buildUtils = index;