vue-cli通过webpack把.txt文件打包到dist文件夹下并且和index.html在同一级目录

使用CopyWebpackPlugin插件,在webpack中copy文件或文件夹

1、下载插件CopyWebpackPlugin

$ npm install copy-webpack-plugin --save-dev

2、在build/webpack.base.conf.js文件下使用插件:

const CopyWebpackPlugin = require('copy-webpack-plugin');

plugins: [
    new CopyWebpackPlugin([
        {
            from: path.join(__dirname, "../***.txt"),
            to: path.join(__dirname, "../dist/***.txt")
        } 
    ])
]

from 要拷贝的文件路径

to 输出路径

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
可以通过修改webpack配置文件来实现这个需求。以下是一个示例webpack配置文件: ```javascript const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { entry: './src/main.js', output: { path: path.resolve(__dirname, 'dist/500'), filename: 'bundle.js' }, plugins: [ new HtmlWebpackPlugin({ filename: '500.html', template: 'index.html' }) ], module: { rules: [ { test: /\.vue$/, loader: 'vue-loader' }, { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ }, { test: /\.(png|jpg|gif|svg)$/, loader: 'file-loader', options: { name: '[name].[ext]?[hash]' } } ] }, resolve: { alias: { 'vue$': 'vue/dist/vue.esm.js' }, extensions: ['*', '.js', '.vue', '.json'] }, devServer: { historyApiFallback: true, noInfo: true, overlay: true }, performance: { hints: false }, devtool: '#eval-source-map' }; // 添加一个钩子函数,用于将list.html文件复制到dist/500文件夹下 module.exports = (env, argv) => { if (argv.mode === 'production') { const fs = require('fs-extra'); fs.copySync('./src/list/list.html', './dist/500/list.html'); } return config; }; ``` 在这个配置文件中,我们通过修改output.path和HtmlWebpackPlugin的配置,将打包后的文件输出到dist/500文件夹下,并将index.html文件重命名为500.html。同时,我们添加了一个钩子函数,在生产模式下,将src/list/list.html复制到dist/500文件夹下。 请注意,如果你使用的是Vue CLI生成的项目,你需要在webpack配置文件中添加一个钩子函数来实现这个需求。不过,一般来说,Vue CLI已经帮你处理好了这个问题,你只需要将list.html文件放到public目录下即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值