mirror of
https://github.com/Tencent/Hippy.git
synced 2026-10-21 08:20:24 +08:00
26e6434b75
- hippy-vue: ElementNode add repaintWithChildren API - hippy-vue: support remove outdated style of HMR chunk - hippy-vue-loader: support style hmr - hippy-vue-css-loader: support remove outdated style of HMR chunk - debug-server, vue-demo, react-demo, hippy-react: support hmr - debug-server: add hippy-dev command
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const Webpack = require('webpack');
|
|
const {
|
|
logger,
|
|
exec,
|
|
} = require('../utils');
|
|
const WebpackDevServer = require('../webpack-dev-server/lib/Server');
|
|
|
|
const startWebpackDevServer = async (args) => {
|
|
const {
|
|
verbose,
|
|
config,
|
|
} = args;
|
|
const { webpackConfig, hmrPort } = getWebpackConfig(config);
|
|
try {
|
|
if (hmrPort) {
|
|
const reversePort = `tcp:${hmrPort}`;
|
|
await exec('adb', ['reverse', reversePort, reversePort]);
|
|
}
|
|
} catch (e) {
|
|
logger.warn('Port reverse failed, For iOS app debug only just ignore the message.');
|
|
logger.warn('Otherwise please check adb devices command working correctly');
|
|
if (verbose) {
|
|
logger.error(e);
|
|
}
|
|
}
|
|
|
|
const compiler = Webpack(webpackConfig);
|
|
const server = new WebpackDevServer(webpackConfig.devServer, compiler);
|
|
await server.start();
|
|
};
|
|
|
|
|
|
function getWebpackConfig(configPath) {
|
|
let hmrPort;
|
|
let webpackConfig;
|
|
const webpackConfigPath = path.resolve(process.cwd(), configPath);
|
|
if (configPath && fs.existsSync(webpackConfigPath)) {
|
|
webpackConfig = require(webpackConfigPath);
|
|
hmrPort = (webpackConfig.devServer && webpackConfig.devServer.port) || 38988;
|
|
}
|
|
return { webpackConfig, hmrPort };
|
|
}
|
|
|
|
|
|
module.exports = { startWebpackDevServer };
|