babel.config.js 1.8 KB

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