123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- 'use strict'
- const path = require('path')
- function resolve(dir) {
- return path.join(__dirname, dir)
- }
- function getNowDate() {
- const date = new Date()
- const year = String(date.getFullYear())
- const month = String(date.getMonth() + 1)
- const day = String(date.getDate())
- return year + month + day
- }
- const nowDate = getNowDate()
- const Timestamp = new Date().getTime()
- const params = nowDate + '-' + Timestamp
- module.exports = {
- publicPath: '/vuepay2', //部署路径后缀
- 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: 'https://smartpark.caih.com/dxapi/', //本地
- changeOrigin: false,
- pathRewrite: {
- '': '/'
- }
- }
- },
- headers: {
- 'Access-Control-Allow-Origin': '*',
- }
- },
- configureWebpack: {
- performance: {
- hints: 'warning',
- // 入口起点的最大体积
- maxEntrypointSize: 50000000,
- // 生成文件的最大体积
- maxAssetSize: 30000000,
- // 只给出 js 文件的性能提示
- assetFilter: function(assetFilename) {
- return assetFilename.endsWith('.js')
- }
- },
- output: { // 输出重构 打包编译后的 文件名称 【模块名称.版本号.时间戳】
- filename: `js/[name].${params}.js`,
- chunkFilename: `js/[name].${params}.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 // 横屏时使用的视口宽度
- })
- ]
- }
- },
- extract: {
- filename: `static/css/[name].${params}.css`,
- chunkFilename: `static/css/[name].${params}.css`
- }
- },
- 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')
- }
- )
- }
- };
|