const path = require('path')
const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const CompressionPlugin = require("compression-webpack-plugin")
let cesiumSource = './node_modules/cesium/Source'
let cesiumWorkers = '../Build/Cesium/Workers'


const plugins = []

module.exports = {
    assetsDir: process.env.VUE_APP_STATIC_URL,
    publicPath: process.env.NODE_ENV === 'production' ? '' : '',
    productionSourceMap: false,
    configureWebpack: config => {
        if (process.env.NODE_ENV === 'production') {
            plugins.push(new CompressionPlugin({
                test: /\.js$|\.html$|.\css/, //匹配文件名
                threshold: 10240, //对超过10k的数据压缩
                deleteOriginalAssets: false //不删除源文件
            }))
        }
        return {
            amd: {
                toUrlUndefined: true
            },
            output: {
                sourcePrefix: ' '
            },
            resolve: {
                alias: {
                    'vue$': 'vue/dist/vue.esm.js',
                    '@': path.resolve('src'),
                    'cesium': path.resolve(__dirname, cesiumSource)
                }
            },
            plugins: [
                new CopyWebpackPlugin([{ from: path.join(cesiumSource, cesiumWorkers), to: 'Workers' }]),
                new CopyWebpackPlugin([{ from: path.join(cesiumSource, 'Assets'), to: 'Assets' }]),
                new CopyWebpackPlugin([{ from: path.join(cesiumSource, 'Widgets'), to: 'Widgets' }]),
                new CopyWebpackPlugin([{ from: path.join(cesiumSource, 'ThirdParty/Workers'), to: 'ThirdParty/Workers' }]),
                new webpack.DefinePlugin({
                    CESIUM_BASE_URL: JSON.stringify('./')
                })
            ].concat(plugins),
            module: {
                unknownContextCritical: /^.\/.*$/,
                unknownContextCritical: false // 6
            }
        }
    },
    devServer: {
        proxy: 'http://192.168.0.248:8082',
    },
    chainWebpack: config => {
        
    }
}