babel.config.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * @Descripttion: babel配置文件
  3. * @version: 1.0.0
  4. * @Author: dream
  5. * @Date: 2021-03-25 15:13:56
  6. * @LastEditors: dream
  7. * @LastEditTime: 2021-03-26 10:26:48
  8. */
  9. const plugins = []
  10. if (process.env.UNI_OPT_TREESHAKINGNG) {
  11. plugins.push(require('@dcloudio/vue-cli-plugin-uni-optimize/packages/babel-plugin-uni-api/index.js'))
  12. }
  13. if (
  14. (
  15. process.env.UNI_PLATFORM === 'app-plus' &&
  16. process.env.UNI_USING_V8
  17. ) ||
  18. (
  19. process.env.UNI_PLATFORM === 'h5' &&
  20. process.env.UNI_H5_BROWSER === 'builtin'
  21. )
  22. ) {
  23. const path = require('path')
  24. const isWin = /^win/.test(process.platform)
  25. const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
  26. const input = normalizePath(process.env.UNI_INPUT_DIR)
  27. try {
  28. plugins.push([
  29. require('@dcloudio/vue-cli-plugin-hbuilderx/packages/babel-plugin-console'),
  30. {
  31. file (file) {
  32. file = normalizePath(file)
  33. if (file.indexOf(input) === 0) {
  34. return path.relative(input, file)
  35. }
  36. return false
  37. }
  38. }
  39. ])
  40. } catch (e) {}
  41. }
  42. process.UNI_LIBRARIES = process.UNI_LIBRARIES || ['@dcloudio/uni-ui']
  43. process.UNI_LIBRARIES.forEach(libraryName => {
  44. plugins.push([
  45. 'import',
  46. {
  47. libraryName: libraryName,
  48. customName: (name) => {
  49. return `${libraryName}/lib/${name}/${name}`
  50. }
  51. }
  52. ])
  53. })
  54. module.exports = {
  55. presets: [
  56. [
  57. '@vue/app',
  58. {
  59. modules: 'commonjs',
  60. useBuiltIns: process.env.UNI_PLATFORM === 'h5' ? 'usage' : 'entry'
  61. }
  62. ]
  63. ],
  64. plugins
  65. }