build.js

// https://github.com/shelljs/shelljs
// 檢查NodeJS和npm的版本
require('./check-versions')()html

process.env.NODE_ENV = 'production'webpack

// Elegant terminal spinner
var ora = require('ora')
var path = require('path')git

// 用於在控制檯輸出帶顏色字體的插件
var chalk = require('chalk')github

// 執行Unix命令行的插件
var shell = require('shelljs')
var webpack = require('webpack')
var config = require('../config')web

var webpackConfig = require('./webpack.prod.conf')shell

var spinner = ora('building for production...')
spinner.start() // 開啓loading動畫npm

// 輸出文件的目標文件夾
var assetsPath = path.join(config.build.assetsRoot, config.build.assetsSubDirectory)字體

// 遞歸刪除舊的目標文件夾動畫

 

shell.rm('-rf', assetsPath)ui

// 從新建立文件夾
shell.mkdir('-p', assetsPath)
shell.config.silent = true
// 將static文件夾複製到輸出的目標文件夾
shell.cp('-R', 'static/*', assetsPath)
shell.config.silent = false

// webpack編譯
webpack(webpackConfig, function (err, stats) {
spinner.stop() // 中止loading動畫
if (err) throw err// 沒有出錯則輸出相關信息

process.stdout.write(stats.toString({
colors: true,
modules: false,
children: false,
chunks: false,
chunkModules: false
}) + '\n\n')

console.log(chalk.cyan(' Build complete.\n')) console.log(chalk.yellow( ' Tip: built files are meant to be served over an HTTP server.\n' + ' Opening index.html over file:// won\'t work.\n' ))})

相關文章
相關標籤/搜索