rollup.config.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* eslint-disable import/no-anonymous-default-export */
  2. import { babel } from '@rollup/plugin-babel';
  3. import commonjs from '@rollup/plugin-commonjs';
  4. import json from '@rollup/plugin-json';
  5. import { nodeResolve } from '@rollup/plugin-node-resolve';
  6. import replace from '@rollup/plugin-replace';
  7. import typescript from '@rollup/plugin-typescript';
  8. import path from 'path';
  9. import cleanup from 'rollup-plugin-cleanup';
  10. export default {
  11. input: 'src/task.ts', // 打包入口
  12. output: {
  13. // 打包出口
  14. name: 'getQueryData', // namespace
  15. file: path.resolve(__dirname, 'public/task/index.js'), // 最终打包出来的文件路径和文件名
  16. format: 'umd', // umd/amd/cjs/iife
  17. },
  18. plugins: [
  19. json(),
  20. nodeResolve({
  21. extensions: ['.js', '.ts'],
  22. }),
  23. // 解析TypeScript
  24. typescript({
  25. tsconfig: path.resolve(__dirname, 'tsconfig.json'),
  26. }),
  27. // 将 CommonJS 转换成 ES2015 模块供 Rollup 处理
  28. commonjs(),
  29. // es6--> es5
  30. babel({
  31. babelHelpers: 'runtime',
  32. exclude: 'node_modules/**',
  33. presets: [['@babel/preset-env', { modules: false }]],
  34. comments: false,
  35. }),
  36. cleanup(),
  37. replace({
  38. 'console.log': '//console.log',
  39. 'process.env.PUBLIC_URL': JSON.stringify(process.env.PUBLIC_URL),
  40. }),
  41. ],
  42. };