'use strict'
= require('./utils'= require('webpack'= require('../config'= require('webpack-merge'= require('path'= require('./webpack.base.conf'= require('copy-webpack-plugin'= require('html-webpack-plugin'= require('friendly-errors-webpack-plugin'= require('portfinder'
const express = require('express'= require('axios'= apiRoutes ='/api'
== process.env.PORT &&const devWebpackConfig =<span style="color: #000000"> merge(baseWebpackConfig,{
module: {
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap,usePostCSS: <span style="color: #0000ff">true<span style="color: #000000"> })
},<span style="color: #008000">//<span style="color: #008000"> cheap-module-eval-source-map is faster for development
<span style="color: #000000"> devtool: config.dev.devtool,<span style="color: #008000">//<span style="color: #008000"> these devServer options should be customized in /config/index.js
<span style="color: #000000"> devServer: {
clientLogLevel: 'warning'<span style="color: #000000">,historyApiFallback: {
rewrites: [
{ from: /.*/,to: path.posix.join(config.dev.assetsPublicPath,'index.html'<span style="color: #000000">) },],},<span style="color: #008000">//<span style="color: #008000">----------------axios 结合 node.js 代理后端请求
<span style="color: #000000"> before(app) {
<span style="color: #008000">//<span style="color: #008000"> 推荐热门歌单
app.get('/api/getDiscList',<span style="color: #0000ff">function<span style="color: #000000">(req,res) {
<span style="color: #0000ff">var url = 'https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg'<span style="color: #000000">
axios.get(url,{
headers: {
referer: 'https://c.y.qq.com/'<span style="color: #000000">,host: 'c.y.qq.com'<span style="color: #000000">
},params: req.query
}).then((response) =><span style="color: #000000"> {
res.json(response.data)
}).<span style="color: #0000ff">catch((e) =><span style="color: #000000"> {
console.log(e)
})
}),<span style="color: #008000">//<span style="color: #008000"> 歌词
app.get('/api/getLyric',res) {
<span style="color: #0000ff">var url = 'https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg'<span style="color: #000000">
axios.get(url,params: req.query
})
.then((response) </span>=><span style="color: #000000"> {
</span><span style="color: #008000">//</span><span style="color: #008000"> jsonp 数据转为 json 数据</span>
<span style="color: #0000ff">var</span> result =<span style="color: #000000"> response.data
</span><span style="color: #0000ff">if</span> (<span style="color: #0000ff">typeof</span> result === 'string'<span style="color: #000000">) {
</span><span style="color: #0000ff">var</span> reg = /^w+(({[^()]+}))$/
<span style="color: #0000ff">var</span> matches =<span style="color: #000000"> result.match(reg)
</span><span style="color: #0000ff">if</span><span style="color: #000000"> (matches) {
result </span>= JSON.parse(matches[1<span style="color: #000000">])
}
}
res.json(result)
</span><span style="color: #008000">//</span><span style="color: #008000"> res.json(response.data)</span>
<span style="color: #000000"> })
.<span style="color: #0000ff">catch((error) =><span style="color: #000000"> {
console.log(error)
})
}),<span style="color: #008000">//<span style="color: #008000">搜索列表接口
<span style="color: #008000">//<span style="color: #008000"> https://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp
app.get('/api/search',res) {
<span style="color: #0000ff">var url = 'https://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp'<span style="color: #000000">
axios.get(url,params: req.query
}).then((response) =><span style="color: #000000"> {
res.json(response.data)
}).<span style="color: #0000ff">catch((e) =><span style="color: #000000"> {
console.log(e)
})
})
},<span style="color: #008000">//<span style="color: #008000">----------------axios 结合 node.js 代理后端请求
hot: <span style="color: #0000ff">true<span style="color: #000000">,contentBase: <span style="color: #0000ff">false,<span style="color: #008000">//<span style="color: #008000"> since we use CopyWebpackPlugin.
compress: <span style="color: #0000ff">true<span style="color: #000000">,host: HOST ||<span style="color: #000000"> config.dev.host,port: PORT ||<span style="color: #000000"> config.dev.port,open: config.dev.autoOpenBrowser,overlay: config.dev.errorOverlay ? { warnings: <span style="color: #0000ff">false,errors: <span style="color: #0000ff">true } : <span style="color: #0000ff">false<span style="color: #000000">,publicPath: config.dev.assetsPublicPath,proxy: config.dev.proxyTable,quiet: <span style="color: #0000ff">true,<span style="color: #008000">//<span style="color: #008000"> necessary for FriendlyErrorsPlugin
<span style="color: #000000"> watchOptions: {
poll: config.dev.poll,}
},plugins: [
<span style="color: #0000ff">new<span style="color: #000000"> webpack.DefinePlugin({
'process.env': require('../config/dev.env'<span style="color: #000000">)
}),<span style="color: #0000ff">new<span style="color: #000000"> webpack.HotModuleReplacementPlugin(),<span style="color: #0000ff">new webpack.NamedModulesPlugin(),<span style="color: #008000">//<span style="color: #008000"> HMR shows correct file names in console on update.
<span style="color: #0000ff">new<span style="color: #000000"> webpack.NoEmitOnErrorsPlugin(),<span style="color: #008000">//<span style="color: #008000"> https://github.com/ampedandwired/html-webpack-plugin
<span style="color: #0000ff">new<span style="color: #000000"> HtmlWebpackPlugin({
filename: 'index.html'<span style="color: #000000">,template: 'index.html'<span style="color: #000000">,inject: <span style="color: #0000ff">true<span style="color: #000000">
}),<span style="color: #008000">//<span style="color: #008000"> copy custom static assets
<span style="color: #0000ff">new<span style="color: #000000"> CopyWebpackPlugin([{
from: path.resolve(__dirname,'../static'<span style="color: #000000">),to: config.dev.assetsSubDirectory,ignore: ['.*'<span style="color: #000000">]
}])
]
})
module.exports = <span style="color: #0000ff">new Promise((resolve,reject) =><span style="color: #000000"> {
portfinder.basePort = process.env.PORT ||<span style="color: #000000"> config.dev.port
portfinder.getPort((err,port) =><span style="color: #000000"> {
<span style="color: #0000ff">if<span style="color: #000000"> (err) {
reject(err)
} <span style="color: #0000ff">else<span style="color: #000000"> {
<span style="color: #008000">//<span style="color: #008000"> publish the new Port,necessary for e2e tests
process.env.PORT =<span style="color: #000000"> port
<span style="color: #008000">//<span style="color: #008000"> add port to devServer config
devWebpackConfig.devServer.port =<span style="color: #000000"> port
</span><span style="color: #008000">//</span><span style="color: #008000"> Add FriendlyErrorsPlugin</span>
devWebpackConfig.plugins.push(<span style="color: #0000ff">new</span><span style="color: #000000"> FriendlyErrorsPlugin({
compilationSuccessInfo: {
messages: [`Your application is running here: http:</span><span style="color: #008000">//</span><span style="color: #008000">${devWebpackConfig.devServer.host}:${port}`],</span>
<span style="color: #000000"> },onErrors: config.dev.notifyOnErrors ?<span style="color: #000000"> utils.createNotifierCallback() : undefined
}))
resolve(devWebpackConfig)
}
})
})