rollup.config.app.js 2.6 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2
const path = require('path')
const alias = require('rollup-plugin-alias')
fxy060608's avatar
fxy060608 已提交
3
const replace = require('rollup-plugin-replace')
fxy060608's avatar
fxy060608 已提交
4
const nodeResolve = require('rollup-plugin-node-resolve')
fxy060608's avatar
fxy060608 已提交
5
const commonjs = require('rollup-plugin-commonjs')
fxy060608's avatar
fxy060608 已提交
6
const requireContext = require('../lib/rollup-plugin-require-context')
fxy060608's avatar
fxy060608 已提交
7

fxy060608's avatar
fxy060608 已提交
8
let input = 'src/platforms/app-plus/service/framework/create-instance-context.js'
fxy060608's avatar
fxy060608 已提交
9 10 11 12 13 14

const output = {
  file: 'packages/uni-app-plus-nvue/dist/index.js',
  format: 'es'
}

fxy060608's avatar
fxy060608 已提交
15 16
const external = []

fxy060608's avatar
init v3  
fxy060608 已提交
17 18 19 20 21 22 23
// if (process.env.UNI_PLATFORM === 'app-plus-nvue') {
//   external.push('vue')
//   output.globals = {
//     vue: 'Vue'
//   }
// }

fxy060608's avatar
fxy060608 已提交
24
if (process.env.UNI_SERVICE === 'legacy') {
fxy060608's avatar
fxy060608 已提交
25
  input = 'src/platforms/app-plus-nvue/services/index.legacy.js'
fxy060608's avatar
fxy060608 已提交
26
  output.file = 'packages/uni-app-plus-nvue/dist/index.legacy.js'
fxy060608's avatar
fxy060608 已提交
27 28
} else {
  input = 'src/platforms/app-plus/service/index.js'
fxy060608's avatar
init v3  
fxy060608 已提交
29 30 31 32 33
  if (process.env.UNI_PLATFORM === 'app-plus') {
    output.file = `packages/uni-app-plus/dist/index.v3.js`
  } else {
    output.file = `packages/uni-app-plus-nvue/dist/index.js`
  }
fxy060608's avatar
fxy060608 已提交
34 35
  output.format = 'iife'
  output.name = 'serviceContext'
fxy060608's avatar
fxy060608 已提交
36
  output.banner =
fxy060608's avatar
fxy060608 已提交
37
    `export function createServiceContext(Vue, weex, plus, __uniConfig, __uniRoutes, UniServiceJSBridge,instanceContext){
fxy060608's avatar
fxy060608 已提交
38
var localStorage = plus.storage
fxy060608's avatar
fxy060608 已提交
39
var setTimeout = instanceContext.setTimeout
fxy060608's avatar
init v3  
fxy060608 已提交
40 41
var clearTimeout = instanceContext.clearTimeout
var setInterval = instanceContext.setInterval
fxy060608's avatar
fxy060608 已提交
42
var clearInterval = instanceContext.clearInterval
fxy060608's avatar
fxy060608 已提交
43 44 45 46 47 48 49 50 51 52
`
  output.footer =
    `
var uni = serviceContext.uni
var getApp = serviceContext.getApp
var getCurrentPages = serviceContext.getCurrentPages

var __registerPage = serviceContext.__registerPage

return serviceContext \n}
fxy060608's avatar
fxy060608 已提交
53
`
fxy060608's avatar
fxy060608 已提交
54
}
fxy060608's avatar
fxy060608 已提交
55

fxy060608's avatar
fxy060608 已提交
56 57
const resolve = dir => path.resolve(__dirname, '../', dir)

fxy060608's avatar
fxy060608 已提交
58
module.exports = {
fxy060608's avatar
fxy060608 已提交
59 60
  input,
  output,
fxy060608's avatar
init v3  
fxy060608 已提交
61 62 63 64 65 66 67 68 69 70 71 72
  plugins: [
    alias({
      // 'vue': resolve('packages/uni-app-plus/dist/service.runtime.esm.js'),
      'uni-core': resolve('src/core'),
      'uni-platform': resolve('src/platforms/' + process.env.UNI_PLATFORM),
      'uni-platforms': resolve('src/platforms'),
      'uni-shared': resolve('src/shared/index.js'),
      'uni-helpers': resolve('src/core/helpers'),
      'uni-invoke-api': resolve('src/platforms/app-plus/service/api'),
      'uni-service-api': resolve('src/core/service/platform-api'),
      'uni-api-protocol': resolve('src/core/helpers/protocol')
    }),
fxy060608's avatar
fxy060608 已提交
73
    nodeResolve(),
fxy060608's avatar
fxy060608 已提交
74
    commonjs(),
fxy060608's avatar
fxy060608 已提交
75
    requireContext(),
fxy060608's avatar
fxy060608 已提交
76 77
    replace({
      __GLOBAL__: 'getGlobalUni()',
fxy060608's avatar
init v3  
fxy060608 已提交
78
      __PLATFORM__: JSON.stringify(process.env.UNI_PLATFORM),
fxy060608's avatar
fxy060608 已提交
79 80
      __PLATFORM_TITLE__: 'app-plus-nvue'
    })
fxy060608's avatar
fxy060608 已提交
81
  ],
fxy060608's avatar
fxy060608 已提交
82
  external
fxy060608's avatar
fxy060608 已提交
83
}