webpack打包dist为gz包

  1. webpack打包可配置开启gz压缩 通常配置在config index.js中 须要插件支持
    tips注意版本--不然会报错
        npm install --save-dev compression-webpack-plugin@1.1.11
    复制代码
    productionGzip: true,
        productionGzipExtensions: ['js', 'css'],
    复制代码
  2. webpack直接打包成.gz包---须要插件支持
    该插件可执行打包,复制,移动,删除文件以及新文件夹在build以前及以后建立。
        cnpm install filemanager-webpack-plugin --save-dev
    复制代码
    webpack配置
    1. 通常在项目 根目录 build/webpack.base.config.js 中 抬头变量声明区域添加
            tips 声明看我的配置
        const FileManagerPlugin = require('filemanager-webpack-plugin')
        2.在根目录 build/webpack.base.config.js 内找到 module.exports。而后在plugins内添加
        (不光支持打包成zip 还能够改为.gz 等主流压缩形式---存放目录可配置--)
        new FileManagerPlugin({
            onEnd: {
                delete: [
                    './dist/control-operate.zip',
                ],
                archive: [
                    {source: './dist', destination: './dist/control-operate.zip'},
                    ]
                }
            })
        tips: 若 plugins不存在,则新建plugins,plugins为数组格式。
            plugins: []
        配置完执行打包命令就ok了
    复制代码
  3. 其余功能(复制,移动-未测试)
    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
                                }
                            }
                        }
                    ]
                }
            })
        ]
    }
    复制代码
  4. 文章来源 www.cnblogs.com/donghuang/p… tips:我是抄的
相关文章
相关标签/搜索