vue-cli中设置webpack系列文章一 ------build.js

build.js

  // 设置process.env.NODE_ENV
  process.env.NODE_ENV = 'production'
  //引入ora,能够完成loading效果
  var ora = require('ora');
  //引入webpack模块
  var webpack = require('webpack');
  //引入path模块
  var path = require('path');
  // 引入rimraf模块
  // "rm -rf"敕令
  var rm = require('rimraf')
  //引入pro环境
  var webpackConfig = require('./webpack.prod.conf');
  //引入大众设置
  var config = require('../config/index');
  
  //加载时显现的文本
  var spinner = ora('building for production...');
  
  //加载动画最先
  spinner.start()
  
  var assetsPath = path.join(config.build.assetsRoot,config.build.assetsSubDirectory);
  // 清空静态资本的二级目录下一切内容
  rm(assetsPath,err=>{
      if (err) throw err
  
      //启动webpack编译临盆环境webpack设置
      webpack(webpackConfig,function (eror,stats) {
          //加载动画完毕
          spinner.stop();
          //// 假如失足,抛失足误
          if(eror) throw eror
  
          // process.stdout规范输出流
          // rocess.stdout.write敕令行窗口向用户显现内容
          // stats.toString(options)返回格式化效果
          process.stdout.write(stats.toString({
                  colors: true,
                  modules: false,
                  children: false,
                  chunks: false,
                  chunkModules: false
              })+'\n')
      })
  
  })
    原文作者:亲爱的阿干
    原文地址: https://segmentfault.com/a/1190000019231647
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞