|
| 1 | +import { resolve } from "path"; |
| 2 | +import { terser } from "rollup-plugin-terser"; |
| 3 | +import { nodeResolve } from "@rollup/plugin-node-resolve"; |
| 4 | +import commonjs from "@rollup/plugin-commonjs"; |
| 5 | +import postcss from "rollup-plugin-postcss"; |
| 6 | +import typescript from "rollup-plugin-typescript2"; |
| 7 | +import json from "@rollup/plugin-json"; |
| 8 | +import replace from "@rollup/plugin-replace"; |
| 9 | +import scss from 'rollup-plugin-scss' |
| 10 | +import autoprefixer from 'autoprefixer' |
| 11 | +import url from '@rollup/plugin-url'; |
| 12 | +const output = resolve(__dirname, "../dist"); |
| 13 | +const getPath = _path => resolve(__dirname, _path); |
| 14 | +// import pkg from "../package.json"; |
| 15 | +//const name = pkg.name; |
| 16 | +const name = 'WebUIPlus'; |
| 17 | +const extensions = [ |
| 18 | + '.js', |
| 19 | + '.ts', |
| 20 | + '.tsx' |
| 21 | +] |
| 22 | +let defaults = { compilerOptions: { declaration: true } }; |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +// 单独打包 |
| 27 | +const config = [ |
| 28 | + { |
| 29 | + input: `./src/index.tsx`, |
| 30 | + plugins: [ |
| 31 | + terser(), |
| 32 | + url({ |
| 33 | + include: ['**/*.svg', '**/*.png', '**/*.jp(e)?g', '**/*.gif', '**/*.webp', '**/*.ttf', '**/*.woff'] |
| 34 | + }), |
| 35 | + nodeResolve(), |
| 36 | + commonjs(), |
| 37 | + postcss({ |
| 38 | + name: 'index', |
| 39 | + extensions: [ '.css', 'scss' ], |
| 40 | + to: `./dist/index.css`, |
| 41 | + plugins: [ |
| 42 | + autoprefixer() |
| 43 | + ], |
| 44 | + // extract: `${output}/${name}/lib/index.css` |
| 45 | + extract: false |
| 46 | + }), |
| 47 | + // tsPlugin, |
| 48 | + typescript({ |
| 49 | + tsconfig: getPath('../tsconfig.build.json'), // 导入本地ts配置 |
| 50 | + tsconfigDefaults: defaults, |
| 51 | + tsconfigOverride: { |
| 52 | + compilerOptions: { |
| 53 | + declaration: true |
| 54 | + } |
| 55 | + }, |
| 56 | + extensions |
| 57 | + }), |
| 58 | + json(), |
| 59 | + replace({ |
| 60 | + preventAssignment: true |
| 61 | + }) |
| 62 | + ], |
| 63 | + output: [ |
| 64 | + { name: name, file: `${output}/index.umd.js`, format: 'umd' }, |
| 65 | + { file: `${output}/index.cjs.js`, format: 'cjs' }, |
| 66 | + { file: `${output}/index.esm.js`, format: 'es' } |
| 67 | + |
| 68 | + ] |
| 69 | + } |
| 70 | +] |
| 71 | + |
| 72 | +export default config; |
0 commit comments