babel.config.js 1.5 KB

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