血透系统PC前端

build-cdn.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. 'use strict'
  2. require('./check-versions')()
  3. process.env.NODE_ENV = 'production'
  4. const ora = require('ora')
  5. const rm = require('rimraf')
  6. const path = require('path')
  7. const chalk = require('chalk')
  8. const webpack = require('webpack')
  9. const config = require('../config')
  10. const webpackConfig = require('./webpack.prod-cdn.conf')
  11. const writeJson = require('write-json')
  12. const QiniuPlugin = require('qiniu-webpack-plugin')
  13. // const utils = require('./utils')
  14. const spinner = ora('building for production...')
  15. spinner.start()
  16. const cdn_ver = require('./cdn.json').version
  17. const addVer = (ver) => {
  18. const ar = ver.split('.')
  19. ar[2] = parseInt(ar[2]) + 1
  20. return ar.join('.')
  21. }
  22. const verNow = addVer(cdn_ver)
  23. webpackConfig.plugins.push(new QiniuPlugin({
  24. ACCESS_KEY: 'E5sYahBxp7RfMECLXhCUZJD3U_BTKYGsPDS4NLFd',
  25. SECRET_KEY: 'mlO3FEmRX-S_9XPCf9WrkvzgnpZ8IlmHeiVrIDQF',
  26. bucket: 'vue',
  27. path: `king/${verNow}/`
  28. }))
  29. webpackConfig.output.publicPath = `//kuyi.shengws.com/king/${verNow}/`
  30. // webpackConfig.output.filename = utils.assetsPath('js/[name].js')
  31. // webpackConfig.output.chunkFilename = utils.assetsPath('js/[id].js')
  32. // console.log(webpackConfig.plugins)
  33. // console.log(typeof webpackConfig.plugins)
  34. // console.log(Object.keys(webpackConfig.plugins))
  35. // webpackConfig.plugins.filter((el)=>{
  36. // console.log(el)
  37. // })
  38. // return
  39. rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
  40. if (err) throw err
  41. console.log('run build')
  42. webpack(webpackConfig, (err, stats) => {
  43. spinner.stop()
  44. if (err) throw err
  45. process.stdout.write(stats.toString({
  46. colors: true,
  47. modules: false,
  48. children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
  49. chunks: false,
  50. chunkModules: false
  51. }) + '\n\n')
  52. if (stats.hasErrors()) {
  53. console.log(chalk.red(' Build failed with errors.\n'))
  54. process.exit(1)
  55. }
  56. console.log('verNow,', verNow)
  57. writeJson.promise(path.join(__dirname, './cdn.json'), {
  58. version: verNow
  59. }).then(function() {
  60. // do stuff
  61. console.log('write cdn.json ok')
  62. })
  63. console.log(chalk.cyan(' Build complete.\n'))
  64. console.log(chalk.yellow(
  65. ' Tip: built files are meant to be served over an HTTP server.\n' +
  66. ' Opening index.html over file:// won\'t work.\n'
  67. ))
  68. })
  69. })