babel.config.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. }
  34. process.UNI_LIBRARIES = process.UNI_LIBRARIES || ['@dcloudio/uni-ui']
  35. process.UNI_LIBRARIES.forEach(libraryName => {
  36. plugins.push([
  37. 'import',
  38. {
  39. 'libraryName': libraryName,
  40. 'customName': (name) => {
  41. return `${libraryName}/lib/${name}/${name}`
  42. }
  43. }
  44. ])
  45. })
  46. module.exports = {
  47. presets: [
  48. [
  49. '@vue/app',
  50. {
  51. modules: 'commonjs',
  52. useBuiltIns: process.env.UNI_PLATFORM === 'h5' ? 'usage' : 'entry'
  53. }
  54. ]
  55. ],
  56. plugins
  57. }