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

const webpack = require('webpack')
const CopyPlugin = require('copy-webpack-plugin')

const HandlerPlugin = require('@hap-toolkit/packager/lib/plugin/handler-plugin')
fxy060608's avatar
fxy060608 已提交
7
const ZipPlugin = require('@hap-toolkit/packager/lib/plugin/zip-plugin')
fxy060608's avatar
fxy060608 已提交
8 9 10 11 12
const NotifyPlugin = require('@hap-toolkit/packager/lib/plugin/notify-plugin')

const Css2jsonPlugin = require('@hap-toolkit/dsl-vue/lib/plugin/css2json-plugin')
const InstVuePlugin = require('@hap-toolkit/dsl-vue/lib/plugin/instvue-plugin')

fxy060608's avatar
fxy060608 已提交
13 14
const InstMainPlugin = require('./plugin/main-plugin')

fxy060608's avatar
fxy060608 已提交
15 16
const parseManifest = require('./manifest/index')

fxy060608's avatar
fxy060608 已提交
17 18 19 20 21 22 23
const env = {
  // 平台:native
  NODE_PLATFORM: 'native',
  // 阶段: dev|test|release
  NODE_PHASE: process.env.NODE_PHASE
}

fxy060608's avatar
fxy060608 已提交
24
const dslFilename = ('vue.' + (process.env.NODE_ENV === 'production' ? 'prod' : 'dev') + '.js')
fxy060608's avatar
fxy060608 已提交
25

fxy060608's avatar
fxy060608 已提交
26
parseManifest(process.UNI_PAGES, process.UNI_MANIFEST)
fxy060608's avatar
fxy060608 已提交
27

fxy060608's avatar
fxy060608 已提交
28
const manifest = global.framework.manifest
fxy060608's avatar
fxy060608 已提交
29 30 31 32 33 34 35

if (!manifest.package) {
  console.error(`maniest.json quickapp 节点缺少 package 配置`)
  process.exit(0)
}

function genPriorities(entryPagePath) {
fxy060608's avatar
fxy060608 已提交
36
  const o = [/^i18n\/.+\.json$/i, 'manifest.json', 'app.js', /^common\//i];
fxy060608's avatar
fxy060608 已提交
37 38 39
  if (entryPagePath) {
    o.splice(3, 0, new RegExp(`^${entryPagePath}/$`), new RegExp(`^${entryPagePath}/.+`))
  } else console.error('未配置入口页面');
fxy060608's avatar
fxy060608 已提交
40 41 42 43 44
  return o
}

module.exports = {
  devtool: false,
fxy060608's avatar
fxy060608 已提交
45 46
  entry() {
    return process.UNI_ENTRY
fxy060608's avatar
fxy060608 已提交
47
  },
fxy060608's avatar
fxy060608 已提交
48 49 50
  externals: {
    vue: 'Vue'
  },
fxy060608's avatar
fxy060608 已提交
51 52 53 54 55 56 57 58 59
  module: {
    rules: [{
      //暂不考虑ts
      test: path.resolve(process.env.UNI_INPUT_DIR, 'main.js'),
      use: [{
        loader: path.resolve(__dirname, 'loader/main-loader')
      }]
    }]
  },
fxy060608's avatar
fxy060608 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
  plugins: [
    new webpack.DefinePlugin({
      // 平台:na
      ENV_PLATFORM: JSON.stringify(env.NODE_PLATFORM),
      // 阶段: dev|test|release
      ENV_PHASE: JSON.stringify(env.NODE_PHASE),
      ENV_PHASE_DV: env.NODE_PHASE === 'dev',
      ENV_PHASE_QA: env.NODE_PHASE === 'test',
      ENV_PHASE_OL: env.NODE_PHASE === 'prod'
    }),
    new CopyPlugin([{
      from: path.resolve(__dirname, '../dist/' + dslFilename),
      to: 'dsl.js'
    }]),
    new HandlerPlugin({}),
    new Css2jsonPlugin(),
    new InstVuePlugin(),
fxy060608's avatar
fxy060608 已提交
77
    new InstMainPlugin(),
fxy060608's avatar
fxy060608 已提交
78 79 80
    new ZipPlugin({
      name: manifest.package,
      icon: manifest.icon,
fxy060608's avatar
fxy060608 已提交
81
      versionCode: manifest.versionCode,
fxy060608's avatar
fxy060608 已提交
82 83
      output: path.resolve(process.env.UNI_OUTPUT_DIR, '..'),
      pathBuild: process.env.UNI_OUTPUT_DIR,
fxy060608's avatar
fxy060608 已提交
84 85
      pathSignFolder: './sign',
      sign: process.env.NODE_ENV === 'production' ? 'release' : 'debug',
fxy060608's avatar
fxy060608 已提交
86
      priorities: genPriorities(manifest.router.entry),
fxy060608's avatar
fxy060608 已提交
87
      subpackages: undefined,
fxy060608's avatar
fxy060608 已提交
88
      comment: '',
fxy060608's avatar
fxy060608 已提交
89 90 91 92 93 94 95
      cwd: process.env.UNI_INPUT_DIR,
      disableStreamPack: undefined,
      disableSubpackages: undefined
    }),
    new NotifyPlugin()
  ]
}