webpack.config.js 2.3 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7
const path = require('path')
const webpack = require('webpack')

const resolve = dir => path.resolve(__dirname, '../', dir)

const pkg = require('../package.json')

fxy060608's avatar
init v3  
fxy060608 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
const externals = {}

if (process.env.UNI_VIEW !== 'true') {
  externals['vue'] = {
    commonjs: 'vue',
    commonjs2: 'vue',
    root: 'Vue'
  }
  externals['vue-router'] = {
    commonjs: 'vue-router',
    commonjs2: 'vue-router',
    root: 'VueRouter'
  }
}

const alias = {
  'uni-core': resolve('src/core'),
  'uni-view': resolve('src/core/view'),
  'uni-service': resolve('src/core/service'),
  'uni-shared': resolve('src/shared'),
  'uni-mixins': resolve('src/core/view/mixins'),
  'uni-helpers': resolve('src/core/helpers'),
  'uni-platform': resolve('src/platforms/' + process.env.UNI_PLATFORM),
  // tree shaking
  'uni-components': resolve('src/core/view/components'),
  'uni-invoke-api': resolve('src/platforms/' + process.env.UNI_PLATFORM + '/service/api'),
  'uni-service-api': resolve('src/core/service/platform-api'),
  'uni-api-protocol': resolve('src/core/helpers/protocol'),
  'uni-api-subscribe': resolve('src/core/view/bridge/subscribe/api/index'),
  // h5 components
  'uni-h5-app-components': resolve('src/platforms/h5/components/app/popup/index'),
  'uni-h5-app-mixins': resolve('src/platforms/h5/components/app/popup/mixins/index'),
  'uni-h5-system-routes': resolve('src/platforms/h5/components/system-routes/index')
}

const provides = {
  'console': [resolve('src/core/helpers/console'), 'default'],
  'UniViewJSBridge': [resolve('src/core/view/bridge/index')],
  'UniServiceJSBridge': [resolve('src/core/service/bridge/index')]
}
if (process.env.UNI_VIEW) { // 方便调试
  delete provides['console']
}
module.exports = function configureWebpack (config) {
  if (process.env.UNI_VIEW === 'true') {
    delete config.externals['vue']
    alias['vue$'] = resolve('packages/uni-app-plus/dist/view.runtime.esm.js')
  }

  return {
    mode: 'production',
    devtool: false,
    externals,
    resolve: {
      alias
    },
    module: {
      rules: []
fxy060608's avatar
fxy060608 已提交
66
    },
fxy060608's avatar
init v3  
fxy060608 已提交
67 68 69 70 71 72 73 74
    plugins: [
      new webpack.DefinePlugin({
        __VERSION__: JSON.stringify(pkg.version),
        __PLATFORM__: JSON.stringify(process.env.UNI_PLATFORM)
      }),
      new webpack.ProvidePlugin(provides)
    ]
  }
fxy060608's avatar
fxy060608 已提交
75
}