babel.config.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const plugins = []
  2. if (process.env.UNI_OPT_TREESHAKINGNG) {
  3. plugins.push(require('@dcloudio/vue-cli-plugin-uni-optimize/packages/babel-plugin-uni-api/index.js'))
  4. }
  5. if (process.env.UNI_PLATFORM === 'app-plus' && process.env.UNI_USING_V8) {
  6. const path = require('path')
  7. const isWin = /^win/.test(process.platform)
  8. const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
  9. const input = normalizePath(process.env.UNI_INPUT_DIR)
  10. try {
  11. plugins.push([
  12. require('@dcloudio/vue-cli-plugin-hbuilderx/packages/babel-plugin-console'),
  13. {
  14. file (file) {
  15. file = normalizePath(file)
  16. if (file.indexOf(input) === 0) {
  17. return path.relative(input, file)
  18. }
  19. return false
  20. }
  21. }
  22. ])
  23. } catch (e) {}
  24. }
  25. process.UNI_LIBRARIES = process.UNI_LIBRARIES || ['@dcloudio/uni-ui']
  26. process.UNI_LIBRARIES.forEach(libraryName => {
  27. plugins.push([
  28. 'import',
  29. {
  30. 'libraryName': libraryName,
  31. 'customName': (name) => {
  32. return `${libraryName}/lib/${name}/${name}`
  33. }
  34. }
  35. ])
  36. })
  37. module.exports = {
  38. presets: [
  39. [
  40. '@vue/app',
  41. {
  42. modules: 'commonjs',
  43. useBuiltIns: process.env.UNI_PLATFORM === 'h5' ? 'usage' : 'entry'
  44. }
  45. ]
  46. ],
  47. plugins
  48. }