首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Vue cli 3在构建后执行一些任务

Vue cli 3在构建后执行一些任务
EN

Stack Overflow用户
提问于 2019-08-19 11:52:13
回答 2查看 2.9K关注 0票数 3

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

代码语言:javascript
复制
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$/)]
  }
}

我需要在生成后删除一些文件以供生产,而且我不知道如何在上检测构建过程。

我没有找到任何这方面的文件。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-08-19 12:19:30

您可以在您的package.json文件中这样做。您可以添加自定义脚本或修改现有脚本。

例如,看看干净的脚本。您可以手动调用此脚本,也可以将其添加到其他脚本中。在本例中,当执行build脚本时执行:

代码语言:javascript
复制
  "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.之后运行

票数 4
EN

Stack Overflow用户

发布于 2019-10-16 05:45:28

添加一个postbuild脚本如何:

代码语言:javascript
复制
  "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"
  }
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57556194

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档