美文网首页
webpack将资源打成zip包

webpack将资源打成zip包

作者: 心中翼 | 来源:发表于2019-02-19 09:32 被阅读0次

    webpack插件:filemanager-webpack-plugin

    该插件允许你复制,打包,移动,删除文件及文件夹在build之前及之后。

    安装:

    npm install filemanager-webpack-plugin --save-dev
    

    资源打zip包 Webpack.config.js:

    const FileManagerPlugin = require('filemanager-webpack-plugin');
    
    new FileManagerPlugin({
      onEnd: {
        mkdir: ['./zip'],
        archive: [
          { source: './dist', destination: './zip/test.zip' },
        ]
      }
    })
    
    image.gif

    其他功能(移动,打包,复制)Webpack.config.js::

    const FileManagerPlugin = require('filemanager-webpack-plugin');
    
    module.exports = {
      ...
      ...
      plugins: [
        new FileManagerPlugin({
          onEnd: {
            copy: [
              { source: '/path/from', destination: '/path/to' },
              { source: '/path/**/*.js', destination: '/path' },
              { source: '/path/fromfile.txt', destination: '/path/tofile.txt' },
              { source: '/path/**/*.{html,js}', destination: '/path/to' },
              { source: '/path/{file1,file2}.js', destination: '/path/to' },
              { source: '/path/file-[hash].js', destination: '/path/to' }
            ],
            move: [
              { source: '/path/from', destination: '/path/to' },
              { source: '/path/fromfile.txt', destination: '/path/tofile.txt' }
            ],
            delete: [
             '/path/to/file.txt',
             '/path/to/directory/'
            ],
            mkdir: [
             '/path/to/directory/',
             '/another/directory/'
            ],
            archive: [
              { source: '/path/from', destination: '/path/to.zip' },
              { source: '/path/**/*.js', destination: '/path/to.zip' },
              { source: '/path/fromfile.txt', destination: '/path/to.zip' },
              { source: '/path/fromfile.txt', destination: '/path/to.zip', format: 'tar' },
              { 
                 source: '/path/fromfile.txt', 
                 destination: '/path/to.tar.gz', 
                 format: 'tar',
                 options: {
                   gzip: true,
                   gzipOptions: {
                    level: 1
                   }
                 }
               }
    
            ]
          }
        })
      ],
      ...
    }
    
    image.gif

    相关文章

      网友评论

          本文标题:webpack将资源打成zip包

          本文链接:https://www.haomeiwen.com/subject/gzxxyqtx.html