我正在使用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$/)]
}
}
我需要在构建后将其删除以用于生产,并且我不知道如何检测到构建过程已结束。
我没有找到任何文档。
答案 0 :(得分:1)
您可以在package.json
文件中执行此操作。您可以添加自定义脚本或修改现有脚本。
例如,查看 clean 脚本。您可以手动调用此脚本,也可以将其添加到另一个脚本中。在此示例中,它在执行 dev 脚本时执行:
"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
之后运行。
答案 1 :(得分:1)
如何添加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"
}