transfer-webpack-plugin最简使用示例

转移文件的插件

加载插件

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

API

new CopyWebpackPlugin(patterns: Array, basePath: String)
  • patterns:数组,每项的格式为{from: 'path', to: 'path'}
    • from:相对于basePath或者当前配置的context(如果basePath路径不存在)的路径
    • to:相对于build即构建目录的路径
  • basePath(可选的):要从参数中解析目录

示例

目录结构

  • build
    • test
  • src
    • test
      • test.js
    • index.js
  • webpack.config.js

配置信息

webpack.config.js

var path = require('path');
var TransferWebpackPlugin = require('transfer-webpack-plugin');

module.exports = {
    entry: path.resolve(__dirname, 'src'),
    output: {
        path: path.resolve(__dirname, 'build'),
        filename: 'app.js'
    },
        context: path.resolve(__dirname, 'src'), //可以不写
    plugins: [
        // 把src/test目录下的文件copy到build/test目录下
        new TransferWebpackPlugin([{
            from: 'test',
            to: 'test'
        }], path.resolve(__dirname, 'src'))
    ]
};

执行命令

$ webpack

参考地址

https://github.com/molforp/transfer-webpack-plugin

转载于:https://www.cnblogs.com/xiaoyucoding/p/7164065.html

你可能感兴趣的:(transfer-webpack-plugin最简使用示例)