This repository has been archived by the owner on Sep 3, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Remove deprecated webpack-serve in favor of using webpack-d…
…ev-server
- Loading branch information
1 parent
741c6f6
commit 481320e
Showing
6 changed files
with
855 additions
and
1,056 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
const isNil = require('lodash/isNil'); | ||
const convert = require('koa-connect'); | ||
const history = require('connect-history-api-fallback'); | ||
const proxy = require('http-proxy-middleware'); | ||
const serve = require('webpack-serve'); | ||
const express = require('express'); | ||
const webpack = require('webpack'); | ||
const WebpackDevServer = require('webpack-dev-server'); | ||
const webpackConfig = require('./webpack/config'); | ||
const settingsConfig = require('./gulp/lib/get-settings-config'); | ||
const projectPath = require('./gulp/lib/project-path'); | ||
|
||
serve({}, { | ||
add: (app, middleware, options) => { | ||
const proxies = settingsConfig.webpack.development.proxies; | ||
const proxies = settingsConfig.webpack.development.proxies; | ||
const proxyConfig = {}; | ||
|
||
if (!isNil(proxies) && proxies.length) { | ||
proxies.forEach(item => { | ||
app.use(convert(proxy(item.path, {target: item.target}))); | ||
}); | ||
} | ||
if (!isNil(proxies) && proxies.length) { | ||
proxies.forEach(item => { | ||
proxyConfig[item.path] = item.target; | ||
}); | ||
} | ||
|
||
if (settingsConfig.webpack.development.historyApiFallback) { | ||
app.use(convert(history())); | ||
} | ||
new WebpackDevServer(webpack(webpackConfig), { | ||
publicPath: webpackConfig.output.publicPath, | ||
hot: true, | ||
historyApiFallback: settingsConfig.webpack.development.historyApiFallback, | ||
proxy: proxyConfig, | ||
stats: { | ||
colors: true, | ||
hash: false, | ||
timings: true, | ||
chunks: false, | ||
chunkModules: false, | ||
modules: false | ||
}, | ||
config: webpackConfig, | ||
content: projectPath(settingsConfig.root.path), | ||
devMiddleware: { | ||
publicPath: webpackConfig.output.publicPath, | ||
stats: { | ||
chunks: false, | ||
chunkModules: false, | ||
colors: true, | ||
hash: false, | ||
modules: false | ||
}, | ||
writeToDisk: true | ||
}, | ||
hotClient: true, | ||
port: settingsConfig.webpack.port | ||
before: app => { | ||
app.use(express.static(projectPath(settingsConfig.root.path))); | ||
} | ||
}).listen(settingsConfig.webpack.port, settingsConfig.env.hostname, err => { | ||
/* eslint-disable no-console */ | ||
if (err) { console.log(err); } | ||
|
||
console.log(`BrowserSync will proxy ${settingsConfig.env.hostname}:${settingsConfig.webpack.port}. Bundling JS using Webpack...`); | ||
/* eslint-enable no-console */ | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.