rollup.config.app.js 2.1 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
fxy060608 已提交
17
if (process.env.UNI_SERVICE === 'legacy') {
fxy060608's avatar
fxy060608 已提交
18
  input = 'src/platforms/app-plus-nvue/services/index.legacy.js'
fxy060608's avatar
fxy060608 已提交
19
  output.file = 'packages/uni-app-plus-nvue/dist/index.legacy.js'
fxy060608's avatar
fxy060608 已提交
20 21 22 23 24
} else {
  input = 'src/platforms/app-plus/service/index.js'
  output.file = 'packages/uni-app-plus-nvue/dist/index.js'
  output.format = 'iife'
  output.name = 'serviceContext'
fxy060608's avatar
fxy060608 已提交
25
  output.banner =
fxy060608's avatar
fxy060608 已提交
26
    `export function createServiceContext(Vue, weex, plus, __uniConfig, __uniRoutes, UniServiceJSBridge){
fxy060608's avatar
fxy060608 已提交
27
var localStorage = plus.storage
fxy060608's avatar
fxy060608 已提交
28 29 30 31 32 33 34 35 36 37 38 39
var setTimeout = global.setTimeout
var clearTimeout = global.clearTimeout
`
  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 已提交
40
`
fxy060608's avatar
fxy060608 已提交
41
}
fxy060608's avatar
fxy060608 已提交
42

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

fxy060608's avatar
fxy060608 已提交
45
module.exports = {
fxy060608's avatar
fxy060608 已提交
46 47
  input,
  output,
fxy060608's avatar
fxy060608 已提交
48
  plugins: [
fxy060608's avatar
fxy060608 已提交
49
    nodeResolve(),
fxy060608's avatar
fxy060608 已提交
50
    commonjs(),
fxy060608's avatar
fxy060608 已提交
51
    requireContext(),
fxy060608's avatar
fxy060608 已提交
52
    alias({
fxy060608's avatar
fxy060608 已提交
53 54 55 56 57
      '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'),
fxy060608's avatar
fxy060608 已提交
58
      'uni-invoke-api': resolve('src/platforms/app-plus/service/api'),
fxy060608's avatar
fxy060608 已提交
59 60
      'uni-service-api': resolve('src/core/service/platform-api'),
      'uni-api-protocol': resolve('src/core/helpers/protocol')
fxy060608's avatar
fxy060608 已提交
61 62 63
    }),
    replace({
      __GLOBAL__: 'getGlobalUni()',
fxy060608's avatar
fxy060608 已提交
64
      __PLATFORM__: JSON.stringify('app-plus'),
fxy060608's avatar
fxy060608 已提交
65 66
      __PLATFORM_TITLE__: 'app-plus-nvue'
    })
fxy060608's avatar
fxy060608 已提交
67
  ],
fxy060608's avatar
fxy060608 已提交
68
  external
fxy060608's avatar
fxy060608 已提交
69
}