copy-webpack-plugin最簡使用示例

拷貝文件的插件webpack

加載插件

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

API

new CopyWebpackPlugin(patterns: Array, options: Object)
  • patterns:數組,最經常使用的每項的格式爲{from: 'path', to: 'path'}
  • options:其它配置。

示例

目錄結構

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

配置信息

webpack.config.jsgit

var path = require('path');
var CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
    entry: path.resolve(__dirname, 'src'),
    output: {
        path: path.resolve(__dirname, 'build'),
        filename: 'app.js'
    },
    context: path.resolve(__dirname, 'src'),
    plugins: [
        new CopyWebpackPlugin([{
            from: 'test/test.js',
            to: 'test'
        }], {
            ignore: [],
            copyUnmodified: true
        })
    ]
};

執行命令github

$ webpack

參考地址

https://github.com/kevlened/copy-webpack-pluginweb

相關文章
相關標籤/搜索