136 lines
4.0 KiB
JavaScript
136 lines
4.0 KiB
JavaScript
'use strict'
|
|
const path = require('path')
|
|
const utils = require('./utils')
|
|
const webpack = require('webpack')
|
|
const config = require('../config')
|
|
const merge = require('webpack-merge')
|
|
const baseWebpackConfig = require('./webpack.base.conf')
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
|
|
const portfinder = require('portfinder')
|
|
|
|
function resolve(dir) {
|
|
return path.join(__dirname, '..', dir)
|
|
}
|
|
|
|
const HOST = process.env.HOST
|
|
const PORT = process.env.PORT && Number(process.env.PORT)
|
|
const local9528 = HOST === '127.0.0.1' && PORT === 9528 && process.env.JY_AI_EMPLOYEE === '1'
|
|
const employeePaths = [
|
|
'/submit/AIEmployeeLogin.ashx',
|
|
'/submit/AICurrentEmployee.ashx',
|
|
'/submit/AIPurchaseInvoiceFile.ashx',
|
|
'/submit/MESCommonBase.ashx',
|
|
'/submit/AIEmployeeLogout.ashx'
|
|
]
|
|
const proxy = Object.assign({}, config.dev.proxyTable)
|
|
if (process.env.JY_AI_EMPLOYEE === '1') {
|
|
employeePaths.forEach(function (route) {
|
|
proxy[route] = {
|
|
target: 'http://127.0.0.1:19529',
|
|
changeOrigin: true,
|
|
logLevel: 'silent',
|
|
bypass: function (req) {
|
|
if (req.url.split('?')[0] !== route) return req.url
|
|
},
|
|
onProxyReq: function (upstream, req) {
|
|
const ticket = (req.headers.cookie || '').split(';').map(value => value.trim())
|
|
.find(value => value.indexOf('JY_AI_EMPLOYEE=') === 0)
|
|
if (ticket) upstream.setHeader('cookie', ticket)
|
|
else upstream.removeHeader('cookie')
|
|
upstream.removeHeader('authorization')
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
const devWebpackConfig = merge(baseWebpackConfig, {
|
|
mode: 'development',
|
|
module: {
|
|
rules: utils.styleLoaders({
|
|
sourceMap: config.dev.cssSourceMap,
|
|
usePostCSS: true
|
|
})
|
|
},
|
|
// cheap-module-eval-source-map is faster for development
|
|
devtool: config.dev.devtool,
|
|
|
|
// these devServer options should be customized in /config/index.js
|
|
devServer: {
|
|
clientLogLevel: 'warning',
|
|
historyApiFallback: true,
|
|
hot: true,
|
|
compress: true,
|
|
host: HOST || config.dev.host,
|
|
port: PORT || config.dev.port,
|
|
open: config.dev.autoOpenBrowser,
|
|
overlay: config.dev.errorOverlay
|
|
? { warnings: false, errors: true }
|
|
: false,
|
|
publicPath: config.dev.assetsPublicPath,
|
|
proxy: proxy,
|
|
quiet: true, // necessary for FriendlyErrorsPlugin
|
|
watchOptions: {
|
|
poll: config.dev.poll
|
|
}
|
|
},
|
|
plugins: [
|
|
new webpack.DefinePlugin({
|
|
'process.env': require('../config/dev.env')
|
|
}),
|
|
new webpack.HotModuleReplacementPlugin(),
|
|
// https://github.com/ampedandwired/html-webpack-plugin
|
|
new HtmlWebpackPlugin({
|
|
filename: 'index.html',
|
|
template: 'index.html',
|
|
inject: true,
|
|
favicon: resolve('favicon.ico'),
|
|
title: 'vue-element-admin',
|
|
templateParameters: {
|
|
BASE_URL: config.dev.assetsPublicPath + config.dev.assetsSubDirectory,
|
|
},
|
|
}),
|
|
]
|
|
})
|
|
|
|
if (local9528) {
|
|
const serviceConfig = resolve('static/config.js')
|
|
devWebpackConfig.module.rules.unshift({
|
|
enforce: 'pre',
|
|
test: file => file === serviceConfig,
|
|
use: [resolve('build/9528-service-loader.js')]
|
|
})
|
|
}
|
|
|
|
module.exports = new Promise((resolve, reject) => {
|
|
portfinder.basePort = process.env.PORT || config.dev.port
|
|
portfinder.getPort((err, port) => {
|
|
if (err || (local9528 && port !== 9528)) {
|
|
reject(err || new Error('本机 9528 端口已被占用'))
|
|
} else {
|
|
// publish the new Port, necessary for e2e tests
|
|
process.env.PORT = port
|
|
// add port to devServer config
|
|
devWebpackConfig.devServer.port = port
|
|
|
|
// Add FriendlyErrorsPlugin
|
|
devWebpackConfig.plugins.push(
|
|
new FriendlyErrorsPlugin({
|
|
compilationSuccessInfo: {
|
|
messages: [
|
|
`Your application is running here: http://${
|
|
devWebpackConfig.devServer.host
|
|
}:${port}`
|
|
]
|
|
},
|
|
onErrors: config.dev.notifyOnErrors
|
|
? utils.createNotifierCallback()
|
|
: undefined
|
|
})
|
|
)
|
|
|
|
resolve(devWebpackConfig)
|
|
}
|
|
})
|
|
})
|