vue项目中使用rimraf dev启动时删除dist目录方式

 更新时间:2022年04月06日 08:39:05   作者:yangdongnan  
这篇文章主要介绍了vue项目中使用rimraf dev启动时删除dist目录方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

使用rimraf dev启动时删除dist目录

适用 vue 2.x vue 3.x已经会在启动时自动删除dist目录

webpack.dev.conf.js

'use strict'
const utils = require('./utils')
const webpack = require('webpack')
const config = require('../config')
const merge = require('webpack-merge')
const rm = require('rimraf')
const path = require('path')
const baseWebpackConfig = require('./webpack.base.conf')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const portfinder = require('portfinder')
//删除dist目录
rm(path.resolve(__dirname, '../dist'),err =>{
  if(err) throw err
})
const HOST = process.env.HOST
const PORT = process.env.PORT && Number(process.env.PORT)
const devWebpackConfig = merge(baseWebpackConfig, {
  module: {
    rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
  },
  // cheap-module-eval-source-map is faster for development
  devtool: config.dev.devtool,
  // these devServer options should be customized in /config/index.js
  devServer: {
    clientLogLevel: 'warning',
    historyApiFallback: {
      rewrites: [
        { from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') },
      ],
    },
    hot: true,
    contentBase: false, // since we use CopyWebpackPlugin.
    compress: true,
    host: HOST || config.dev.host,
    port: PORT || config.dev.port,
    open: config.dev.autoOpenBrowser,
    overlay: config.dev.errorOverlay
      ? { warnings: false, errors: true }
      : false,
    publicPath: config.dev.assetsPublicPath,
    proxy: config.dev.proxyTable,
    quiet: true, // necessary for FriendlyErrorsPlugin
    watchOptions: {
      poll: config.dev.poll,
    }
  },
  plugins: [
    new webpack.DefinePlugin({
      'process.env': require('../config/dev.env')
    }),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
    new webpack.NoEmitOnErrorsPlugin(),
    // https://github.com/ampedandwired/html-webpack-plugin
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: 'index.html',
      inject: true
    }),
    // copy custom static assets
    new CopyWebpackPlugin([
      {
        from: path.resolve(__dirname, '../static'),
        to: config.dev.assetsSubDirectory,
        ignore: ['.*']
      }
    ]),
  ]
})
module.exports = new Promise((resolve, reject) => {
  portfinder.basePort = process.env.PORT || config.dev.port
  portfinder.getPort((err, port) => {
    if (err) {
      reject(err)
    } else {
      // publish the new Port, necessary for e2e tests
      process.env.PORT = port
      // add port to devServer config
      devWebpackConfig.devServer.port = port
      // Add FriendlyErrorsPlugin
      devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
        compilationSuccessInfo: {
          messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
        },
        onErrors: config.dev.notifyOnErrors
        ? utils.createNotifierCallback()
        : undefined
      }))
      resolve(devWebpackConfig)
    }
  })
})

vue修改dist目录

前后端分析之后,前端 打包处理 

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。 

相关文章

  • vue+Element-ui实现分页效果实例代码详解

    vue+Element-ui实现分页效果实例代码详解

    这篇文章主要介绍了vue+Element-ui实现分页效果 ,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2018-12-12
  • vue实现多个tab标签页的切换与关闭详细代码

    vue实现多个tab标签页的切换与关闭详细代码

    这篇文章主要给大家介绍了关于vue实现多个tab标签页的切换与关闭的相关资料,使用vue.js实现tab切换很简单,文中通过代码示例介绍的非常详细,需要的朋友可以参考下
    2023-10-10
  • Vue实战之掌握自定义指令

    Vue实战之掌握自定义指令

    作为使用Vue的开发者,我们对Vue指令一定不陌生,诸如v-model、v-on、v-for、v-if等,同时Vue也为开发者提供了自定义指令的api,熟练的使用自定义指令可以极大的提高了我们编写代码的效率,让我们可以节省时间开心的摸鱼
    2022-11-11
  • vue+vuex+axios从后台获取数据存入vuex,组件之间共享数据操作

    vue+vuex+axios从后台获取数据存入vuex,组件之间共享数据操作

    这篇文章主要介绍了vue+vuex+axios从后台获取数据存入vuex,组件之间共享数据操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-07-07
  • vue2.0 elementUI制作面包屑导航栏

    vue2.0 elementUI制作面包屑导航栏

    本篇文章主要给大家详细代码讲解了vue2.0 elementUI制作面包屑导航栏的过程,对此有兴趣的朋友可以学习下。
    2018-02-02
  • 基于Vue3实现无限滚动组件的示例代码

    基于Vue3实现无限滚动组件的示例代码

    如果你在社交媒体上停留的时间过长,那么,你所在的网站很可能正在使用无限滚动组件。这篇文章教你利用Vue3实现无限滚动组件,感兴趣的可以参考一下
    2022-09-09
  • 浅谈Vue.js 中的 v-on 事件指令的使用

    浅谈Vue.js 中的 v-on 事件指令的使用

    这篇文章主要介绍了浅谈Vue.js 中的 v-on 事件指令的使用,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-11-11
  • Vue+Element-ui日历排班自定义实例代码

    Vue+Element-ui日历排班自定义实例代码

    这篇文章主要给大家介绍了关于Vue+Element-ui日历排班自定义的相关资料,有现成的日历插件但是不符合需求,所以项目中使用vue+element的表格组件自己实现一个日历组件,需要的朋友可以参考下
    2023-09-09
  • 详解vue3中虚拟列表组件的实现

    详解vue3中虚拟列表组件的实现

    这篇文章主要为大家详细介绍了vue3中实现虚拟列表组件的相关知识,包含加载更多以及loading状态,文中的示例代码讲解详细,感兴趣的小伙伴可以了解一下
    2023-10-10
  • 全面详解vue种数组去重的12种方法示例

    全面详解vue种数组去重的12种方法示例

    这篇文章主要介绍了vue数组去重的12种方法示例全面详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-07-07

最新评论