/** * @Author: Caven * @Date: 2018-12-15 00:33:19 */ 'use strict' const path = require('path') const CopyWebpackPlugin = require('copy-webpack-plugin') const CompressionPlugin = require('compression-webpack-plugin') const dtSdk = './node_modules/dt-sdk' let resolve = dir => { return path.resolve(__dirname, dir) } module.exports = { lintOnSave: false, publicPath: './', productionSourceMap: false, configureWebpack: { module: { unknownContextCritical: false }, resolve: { alias: { '@': resolve('src'), '@public': resolve('public') } }, performance: { hints: false }, // optimization:{ // runtimeChunk: 'single', // // 分离 js // splitChunks: { // chunks: 'all', // maxInitialRequests: Infinity, // minSize: 20000, // cacheGroups: { // vendor: { // test: /[\\/]node_modules[\\/]/, // name (module) { // // get the name. E.g. node_modules/packageName/not/this/part.js // // or node_modules/packageName // const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1] // // npm package names are URL-safe, but some servers don't like @ symbols // return `npm.${packageName.replace('@', '')}` // } // } // } // } // }, plugins: [ // // 压缩成 .gz 文件 new CompressionPlugin({ filename: '[path][base].gz', algorithm: 'gzip', test: /\.js$|\.css$|\.html$/, threshold: 10240, minRatio: 0.8 }) // 压缩成 .br 文件,如果 zlib 报错无法解决,可以注释这段使用代码,一般本地没问题,需要注意线上服务器会可能发生找不到 zlib 的情况。 // new CompressionPlugin({ // filename: '[path][base].br', // algorithm: 'brotliCompress', // test: /\.(js|css|html|svg)$/, // compressionOptions: { // params: { // [zlib.constants.BROTLI_PARAM_QUALITY]: 11 // } // }, // threshold: 10240, // minRatio: 0.8 // }) ] }, chainWebpack: config => { config.resolve.extensions .add('.js') .add('.vue') .end() config.module .rule('images') .test(/\.(png|jpe?g|gif)(\?.*)?$/) .use('url-loader') .loader('url-loader') .options({ name: 'images/[name].[ext]', limit: 10000, esModule: false }) .end() config.module .rule('fonts') .test(/\.(eot|ttf|woff|woff2)(\?.*)?$/) .use('url-loader') .loader('url-loader') .options({ name: 'fonts/[name].[ext]', limit: 10000 }) .end() config.module .rule('svg') .exclude.add(resolve('src/assets/svg/icons')) .end() config.module .rule('icons') .test(/\.svg$/) .include.add(resolve('src/assets/svg/icons')) .end() .use('svg-sprite-loader') .loader('svg-sprite-loader') .options({ symbolId: 'icon-[name]' }) .end() config.plugin('copy').use(CopyWebpackPlugin, [ [ { from: path.join(__dirname, 'public'), to: path.join(__dirname, 'dist'), ignore: ['index.html'] }, { from: path.join(dtSdk, 'library/Workers'), to: 'Workers' }, { from: path.join(dtSdk, 'library/ThirdParty'), to: 'ThirdParty' }, { from: path.join(dtSdk, 'library/Assets'), to: 'Assets' }, { from: path.join(dtSdk, 'library/Widgets'), to: 'Widgets' } ] ]) config.plugin('define').tap(args => { args[0].CESIUM_BASE_URL = JSON.stringify('') return args }) }, devServer: { open: true }, css: { loaderOptions: { postcss: { // plugins: [ // require('postcss-pxtorem')({ // rootValue: 192, // 正常适配 // // rootValue: 280, // 3840 * 2160 // propList: ['*'], // 可以从px更改为rem的属性 // selectorBlackList: [ // // 匹配不被转换为rem的选择器 // 'super-cesium-timeline-icon16' // // 'card-position' // ] // }) // ] } } } }