babel.config.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. console.log(e)
  25. }
  26. }
  27. process.UNI_LIBRARIES = process.UNI_LIBRARIES || ['@dcloudio/uni-ui']
  28. process.UNI_LIBRARIES.forEach(libraryName => {
  29. plugins.push([
  30. 'import',
  31. {
  32. libraryName: libraryName,
  33. customName: (name) => {
  34. return `${libraryName}/lib/${name}/${name}`
  35. }
  36. }
  37. ])
  38. })
  39. module.exports = {
  40. presets: [
  41. [
  42. '@vue/app',
  43. {
  44. modules: 'commonjs',
  45. useBuiltIns: process.env.UNI_PLATFORM === 'h5' ? 'usage' : 'entry'
  46. }
  47. ]
  48. ],
  49. plugins
  50. }