【问题标题】:Vue cli 3 do some tasks after buildVue cli 3 在构建后执行一些任务
【发布时间】:2019-12-24 15:23:17
【问题描述】:

我正在使用vue cli 3,这是我的vue.config.js

const path = require('path')
const webpack = require('webpack')
const publicDir = 'public'
const isProduction = process.env.NODE_ENV === 'production'
module.exports = {
  publicPath: isProduction ? './dist/' : '',
  outputDir: 'public/dist',
  indexPath: '../../resources/views/index.blade.php',
  filenameHashing: true,
  chainWebpack: config => {
    config
      .entry('app')
      .clear()
      .add('./resources/vue/main.js')
      .end()
    config.module
      .rule('graphql')
      .test(/\.gql$/)
      .use('graphql-tag/loader')
      .loader('graphql-tag/loader')
      .end()
  },
  configureWebpack: {
    plugins: [new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)]
  }
}

构建后我需要删除一些文件进行生产,我不知道如何检测构建过程是否结束

我没有找到任何关于此的文档。

【问题讨论】:

    标签: vue.js vue-cli vue-cli-3


    【解决方案1】:

    您可以在 package.json 文件中执行此操作。您可以添加自定义脚本或修改现有脚本。

    例如看看 clean 脚本。您可以手动调用此脚本,或将其添加到另一个脚本中。在此示例中,它在执行 build 脚本时执行:

      "scripts": {
        "serve": "vue-cli-service serve",
        "watch": "vue-cli-service build --mode development --watch",
        "dev": "vue-cli-service --mode development build",
        "build": "vue-cli-service build && npm run clean",
        "lint": "vue-cli-service lint",
        "clean": "rm -rf ../public/dist"
      },
      ...
    

    注意&& 使它们按顺序运行clean 将在build 之后运行

    【讨论】:

    • 这不是我想要的,但它有效,这就足够了:))谢谢
    【解决方案2】:

    添加一个postbuild 脚本怎么样:

      "scripts": {
        "serve": "vue-cli-service serve",
        "build": "vue-cli-service build",
        "postbuild": "rm dist/<file-to-delete>", // <--- add this one
        "lint": "vue-cli-service lint",
        "test:e2e": "vue-cli-service test:e2e",
        "test:unit": "vue-cli-service test:unit"
      }
    

    【讨论】:

    猜你喜欢
    • 2016-10-26
    • 2015-08-31
    • 2021-10-26
    • 2015-12-04
    • 2020-04-13
    • 2019-04-20
    • 1970-01-01
    • 2021-12-12
    • 2018-04-12
    相关资源
    最近更新 更多