提交 432625a2 编写于 作者: fxy060608's avatar fxy060608

feat(h5): automator

上级 3eb5e84d
......@@ -35,17 +35,7 @@ module.exports = (api, options) => {
}
}
const port = args['auto-port'] || process.env.UNI_AUTOMATOR_PORT
if (port) {
const host = args['auto-host'] || process.env.UNI_AUTOMATOR_HOST || '0.0.0.0'
const prepareURLs = require('@vue/cli-service/lib/util/prepareURLs')
const urls = prepareURLs('ws', host, port, '')
if (urls.lanUrlForConfig) {
process.env.UNI_AUTOMATOR_WS_ENDPOINT = 'ws://' + urls.lanUrlForConfig + ':' + port
} else {
process.env.UNI_AUTOMATOR_WS_ENDPOINT = urls.localUrlForBrowser
}
}
require('./util').initAutomator(args)
args.entry = args.entry || args._[0]
......
......@@ -21,10 +21,14 @@ module.exports = (api, options) => {
'--host': `specify host (default: ${defaults.host})`,
'--port': `specify port (default: ${defaults.port})`,
'--https': `use https (default: ${defaults.https})`,
'--public': 'specify the public network URL for the HMR client'
'--public': 'specify the public network URL for the HMR client',
'--auto-host': 'specify automator host',
'--auto-port': 'specify automator port'
}
}, async function serve (args) {
info('Starting development server...')
info('Starting development server...')
require('./util').initAutomator(args)
// although this is primarily a dev server, it is possible that we
// are running it in a mode with a production env, e.g. in E2E tests.
......
module.exports = {
initAutomator (args) {
const port = args['auto-port'] || process.env.UNI_AUTOMATOR_PORT
if (port) {
const host = args['auto-host'] || process.env.UNI_AUTOMATOR_HOST || '0.0.0.0'
const prepareURLs = require('@vue/cli-service/lib/util/prepareURLs')
const urls = prepareURLs('ws', host, port, '')
if (urls.lanUrlForConfig) {
process.env.UNI_AUTOMATOR_WS_ENDPOINT = 'ws://' + urls.lanUrlForConfig + ':' + port
} else {
process.env.UNI_AUTOMATOR_WS_ENDPOINT = urls.localUrlForBrowser
}
}
}
}
......@@ -116,7 +116,8 @@ module.exports = {
loader: path.resolve(__dirname, '../../packages/wrap-loader'),
options: {
before: [
beforeCode + statCode + getGlobalUsingComponentsCode()
beforeCode + require('../util').getAutomatorCode() + statCode +
getGlobalUsingComponentsCode()
]
}
}]
......@@ -179,4 +180,4 @@ module.exports = {
require('./cssnano-options')(webpackConfig)
}
}
}
}
......@@ -81,9 +81,6 @@ module.exports = {
const beforeCode = 'import \'uni-pages\';'
const automator = `@dcloudio/uni-${process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM}/dist/automator`
const automatorCode = process.env.UNI_AUTOMATOR_WS_ENDPOINT ? `import '${automator}';` : ''
return {
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
entry () {
......@@ -112,7 +109,7 @@ module.exports = {
loader: path.resolve(__dirname, '../../packages/wrap-loader'),
options: {
before: [
beforeCode + automatorCode + statCode
beforeCode + require('../util').getAutomatorCode() + statCode
]
}
}, {
......@@ -200,4 +197,4 @@ module.exports = {
webpackConfig.plugins.delete('preload')
webpackConfig.plugins.delete('prefetch')
}
}
}
......@@ -12,5 +12,9 @@ module.exports = {
})
}
return partialIdentifier
},
getAutomatorCode () {
const automator = `@dcloudio/uni-${process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM}/dist/automator`
return process.env.UNI_AUTOMATOR_WS_ENDPOINT ? `import '${automator}';` : ''
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册