'use strict'
const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')
configureWebpack: {
    plugins: [
        new CopyWebpackPlugin([{
                from: 'node_modules/@easydarwin/easyplayer/dist/component/EasyPlayer.swf',
                to: './libs/EasyPlayer/'
            },
            {
                from: 'node_modules/@easydarwin/easyplayer/dist/component/crossdomain.xml',
                to: './libs/EasyPlayer/'
            },
            {
                from: 'node_modules/@easydarwin/easyplayer/dist/component/EasyPlayer-lib.min.js',
                to: './libs/EasyPlayer/'
            }
        ])
    ]
}

function resolve(dir) {
    return path.join(__dirname, dir)
}
module.exports = {
    publicPath: '/', //部署路径后缀
    assetsDir: 'static', // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录。
    indexPath: 'index.html', // 指定生成的 index.html 的输出路径 (相对于 outputDir)。也可以是一个绝对路径。
    filenameHashing: true, // 文件名hash，默认
    lintOnSave: false, // 开发环境下通过 eslint-loader 在每次保存时 lint 代码
    productionSourceMap: false, // 关闭生产环境的 source map
    devServer: {
        overlay: {
            // 让浏览器 overlay 同时显示警告和错误
            warnings: true,
            errors: true
        },
        //host: '172.16.120.200',
        host: '0.0.0.0',
        port: 8080, // 端口号
        // https: false, // https:{type:Boolean}
        open: true, // 配置自动启动浏览器
        hotOnly: true, // 热更新
        proxy: {
            // 配置多个跨域
            '/': {
                target: 'https://smartpark.caih.com/dxapi/', //东信
                //target: 'http://172.16.120.104:8085/', //本地
                changeOrigin: false,
                pathRewrite: {
                    '': '/'
                }
            }
        },
        headers: {
            'Access-Control-Allow-Origin': '*',
        }
    },
    configureWebpack: {
        performance: {
            hints: 'warning',
            // 入口起点的最大体积
            maxEntrypointSize: 150000000,
            // 生成文件的最大体积
            maxAssetSize: 130000000,
            // 只给出 js 文件的性能提示
            assetFilter: function(assetFilename) {
                return assetFilename.endsWith('.js')
            }
        }
    },
    css: {
        loaderOptions: {
            postcss: {
                plugins: [
                    require('postcss-px-to-viewport')({
                        unitToConvert: 'px', // 需要转换的单位，默认为"px"
                        viewportWidth: 375, //  设计稿的视口宽度
                        unitPrecision: 5, // 单位转换后保留的精度
                        propList: ['*'], // 能转化为vw的属性列表
                        viewportUnit: 'vw', //  希望使用的视口单位
                        fontViewportUnit: 'vw', // 字体使用的视口单位
                        selectorBlackList: [], // 需要忽略的CSS选择器
                        minPixelValue: 1, // 最小的转换数值，如果为1的话，只有大于1的值会被转换
                        mediaQuery: false, // 媒体查询里的单位是否需要转换单位
                        replace: true, // 是否直接更换属性值，而不添加备用属性
                        exclude: /node_modules/, // 忽略某些文件夹下的文件或特定文件
                        include: undefined, // 如果设置了include，那将只有匹配到的文件才会被转换，例如只转换 'src/mobile' 下的文件 (include: /\/src\/mobile\//)
                        landscape: false, // 是否添加根据 landscapeWidth 生成的媒体查询条件 @media (orientation: landscape)
                        landscapeUnit: 'vw', // 横屏时使用的单位
                        landscapeWidth: 667 // 横屏时使用的视口宽度
                    })
                ]
            }
        }
    },
    chainWebpack(config) {
        // it can improve the speed of the first screen, it is recommended to turn on preload
        config.plugin('preload').tap(() => [{
            rel: 'preload',
            // to ignore runtime.js
            // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
            fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
            include: 'initial'
        }])

        // when there are many pages, it will cause too many meaningless requests
        config.plugins.delete('prefetch')

        // set svg-sprite-loader
        config.module
            .rule('svg')
            .exclude.add(resolve('src/assets/icons'))
            .end()
        config.module
            .rule('icons')
            .test(/\.svg$/)
            .include.add(resolve('src/assets/icons'))
            .end()
            .use('svg-sprite-loader')
            .loader('svg-sprite-loader')
            .options({
                symbolId: 'icon-[name]'
            })
            .end()

        config
            .when(process.env.NODE_ENV !== 'development',
                config => {
                    config
                        .plugin('ScriptExtHtmlWebpackPlugin')
                        .after('html')
                        .use('script-ext-html-webpack-plugin', [{
                            // `runtime` must same as runtimeChunk name. default is `runtime`
                            inline: /runtime\..*\.js$/
                        }])
                        .end()
                    config
                        .optimization.splitChunks({
                            chunks: 'all',
                            cacheGroups: {
                                libs: {
                                    name: 'chunk-libs',
                                    test: /[\\/]node_modules[\\/]/,
                                    priority: 10,
                                    chunks: 'initial' // only package third parties that are initially dependent
                                },
                                elementUI: {
                                    name: 'chunk-elementUI', // split elementUI into a single package
                                    priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
                                    test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
                                },
                                commons: {
                                    name: 'chunk-commons',
                                    test: resolve('src/components'), // can customize your rules
                                    minChunks: 3, //  minimum common number
                                    priority: 5,
                                    reuseExistingChunk: true
                                }
                            }
                        })
                        // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
                    config.optimization.runtimeChunk('single')
                }
            )
    },



};