diff --git a/CHANGELOG.md b/CHANGELOG.md index bd32f1f3..67309c5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,15 @@ + + + + + + + + + diff --git a/lerna.json b/lerna.json index e18d6b11..c44e2ce4 100644 --- a/lerna.json +++ b/lerna.json @@ -18,5 +18,5 @@ "PR: Underlying Tools": ":hammer: Underlying Tools" } }, - "version": "2.1.32" + "version": "2.1.33-2" } diff --git a/package.json b/package.json index 8ce5b979..031c7867 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "root", - "version": "2.1.32", + "version": "2.1.33-2", "private": true, "workspaces": [ "packages/*" diff --git a/packages/cli-shared-utils/package.json b/packages/cli-shared-utils/package.json index cc4f94e1..1af0295d 100644 --- a/packages/cli-shared-utils/package.json +++ b/packages/cli-shared-utils/package.json @@ -1,6 +1,6 @@ { "name": "@mpxjs/cli-shared-utils", - "version": "2.1.32", + "version": "2.1.33-2", "description": "share utils for mpx-cli", "main": "lib/index.js", "dependencies": { diff --git a/packages/mpx-cli-service/package.json b/packages/mpx-cli-service/package.json index 972baa17..145b4714 100644 --- a/packages/mpx-cli-service/package.json +++ b/packages/mpx-cli-service/package.json @@ -1,13 +1,13 @@ { "name": "@mpxjs/mpx-cli-service", - "version": "2.1.32", + "version": "2.1.33-2", "description": "local service for mpx-cli project", "main": "lib/Service.js", "bin": { "mpx-cli-service": "bin/mpx-cli-service.js" }, "dependencies": { - "@mpxjs/cli-shared-utils": "^2.1.32", + "@mpxjs/cli-shared-utils": "^2.1.33-2", "@vue/cli-service": "^5.0.0", "@vue/cli-shared-utils": "^5.0.4", "minimist": "^1.2.5" diff --git a/packages/vue-cli-plugin-mpx-cloud-func/package.json b/packages/vue-cli-plugin-mpx-cloud-func/package.json index 36ff947d..e71bf326 100644 --- a/packages/vue-cli-plugin-mpx-cloud-func/package.json +++ b/packages/vue-cli-plugin-mpx-cloud-func/package.json @@ -1,6 +1,6 @@ { "name": "@mpxjs/vue-cli-plugin-mpx-cloud-func", - "version": "2.1.32", + "version": "2.1.33-2", "description": "mp cloud func plugin for mpx", "main": "index.js", "scripts": { diff --git a/packages/vue-cli-plugin-mpx-e2e-test/package.json b/packages/vue-cli-plugin-mpx-e2e-test/package.json index 4863777f..e9b1a800 100644 --- a/packages/vue-cli-plugin-mpx-e2e-test/package.json +++ b/packages/vue-cli-plugin-mpx-e2e-test/package.json @@ -1,6 +1,6 @@ { "name": "@mpxjs/vue-cli-plugin-mpx-e2e-test", - "version": "2.1.32", + "version": "2.1.33-2", "description": "e2e plugin for mpx", "main": "index.js", "scripts": { diff --git a/packages/vue-cli-plugin-mpx-eslint/package.json b/packages/vue-cli-plugin-mpx-eslint/package.json index 4851ea29..3b04c996 100644 --- a/packages/vue-cli-plugin-mpx-eslint/package.json +++ b/packages/vue-cli-plugin-mpx-eslint/package.json @@ -1,6 +1,6 @@ { "name": "@mpxjs/vue-cli-plugin-mpx-eslint", - "version": "2.1.32", + "version": "2.1.33-2", "description": "eslint plugin for mpx-cli", "main": "index.js", "scripts": { diff --git a/packages/vue-cli-plugin-mpx-plugin-mode/package.json b/packages/vue-cli-plugin-mpx-plugin-mode/package.json index 26f38863..b43f0e16 100644 --- a/packages/vue-cli-plugin-mpx-plugin-mode/package.json +++ b/packages/vue-cli-plugin-mpx-plugin-mode/package.json @@ -1,6 +1,6 @@ { "name": "@mpxjs/vue-cli-plugin-mpx-plugin-mode", - "version": "2.1.32", + "version": "2.1.33-2", "description": "", "main": "index.js", "scripts": { diff --git a/packages/vue-cli-plugin-mpx-ssr/package.json b/packages/vue-cli-plugin-mpx-ssr/package.json index 73df10b9..db430248 100644 --- a/packages/vue-cli-plugin-mpx-ssr/package.json +++ b/packages/vue-cli-plugin-mpx-ssr/package.json @@ -1,6 +1,6 @@ { "name": "@mpxjs/vue-cli-plugin-mpx-ssr", - "version": "2.1.32", + "version": "2.1.33-2", "description": " web ssr plugin for mpx-cli", "main": "index.js", "scripts": { @@ -9,8 +9,8 @@ "dependencies": { "memory-fs": "^0.5.0", "fs-extra": "^9.1.0", - "@mpxjs/vue-cli-plugin-mpx": "^2.1.32", - "@mpxjs/cli-shared-utils": "^2.1.32" + "@mpxjs/vue-cli-plugin-mpx": "^2.1.33-2", + "@mpxjs/cli-shared-utils": "^2.1.33-2" }, "devDependencies": { "axios": "^1.6.0", diff --git a/packages/vue-cli-plugin-mpx-theme/package.json b/packages/vue-cli-plugin-mpx-theme/package.json index 7bc2e389..02c3b0d4 100644 --- a/packages/vue-cli-plugin-mpx-theme/package.json +++ b/packages/vue-cli-plugin-mpx-theme/package.json @@ -1,6 +1,6 @@ { "name": "@mpxjs/vue-cli-plugin-mpx-theme", - "version": "2.1.32", + "version": "2.1.33-2", "description": "mpx theme plugin for mpx-cli", "main": "index.js", "scripts": { diff --git a/packages/vue-cli-plugin-mpx-typescript/package.json b/packages/vue-cli-plugin-mpx-typescript/package.json index b209def6..5154f995 100644 --- a/packages/vue-cli-plugin-mpx-typescript/package.json +++ b/packages/vue-cli-plugin-mpx-typescript/package.json @@ -1,6 +1,6 @@ { "name": "@mpxjs/vue-cli-plugin-mpx-typescript", - "version": "2.1.32", + "version": "2.1.33-2", "description": "typescript plugin for mpx-cli", "main": "index.js", "scripts": { diff --git a/packages/vue-cli-plugin-mpx-unit-test/package.json b/packages/vue-cli-plugin-mpx-unit-test/package.json index 3b3ddcb9..ff0d3af7 100644 --- a/packages/vue-cli-plugin-mpx-unit-test/package.json +++ b/packages/vue-cli-plugin-mpx-unit-test/package.json @@ -1,6 +1,6 @@ { "name": "@mpxjs/vue-cli-plugin-mpx-unit-test", - "version": "2.1.32", + "version": "2.1.33-2", "description": "unit-test for mpx-cli", "main": "index.js", "scripts": { diff --git a/packages/vue-cli-plugin-mpx-utility-first-css/package.json b/packages/vue-cli-plugin-mpx-utility-first-css/package.json index 97883fde..7fc88a91 100644 --- a/packages/vue-cli-plugin-mpx-utility-first-css/package.json +++ b/packages/vue-cli-plugin-mpx-utility-first-css/package.json @@ -1,6 +1,6 @@ { "name": "@mpxjs/vue-cli-plugin-mpx-utility-first-css", - "version": "2.1.32", + "version": "2.1.33-2", "description": "utility-first css plugin for mpx-cli", "main": "index.js", "scripts": { diff --git a/packages/vue-cli-plugin-mpx/commands/serve/mp.js b/packages/vue-cli-plugin-mpx/commands/serve/mp.js index a3a65acf..0cb57ba7 100644 --- a/packages/vue-cli-plugin-mpx/commands/serve/mp.js +++ b/packages/vue-cli-plugin-mpx/commands/serve/mp.js @@ -3,15 +3,42 @@ const { getCurrentTarget } = require('@mpxjs/cli-shared-utils') const { symlinkTargetConfig } = require('../../utils/symlink') const { handleWebpackDone } = require('../../utils/webpack') const { resolveServeWebpackConfigByTarget } = require('../../config/index') +const { createDevServer } = require('./utils') /** @type {import('@vue/cli-service').ServicePlugin} */ module.exports.serveMp = async function serveMp (api, options, args) { const target = getCurrentTarget() // 小程序构建配置 - const webpackConfigs = await resolveServeWebpackConfigByTarget(api, options, target, args) + const webpackConfigs = await resolveServeWebpackConfigByTarget( + api, + options, + target, + args + ) + + // create compiler + const compiler = webpack(webpackConfigs) + + // resolve devServer options + const projectDevServerOptions = webpackConfigs[0].devServer || {} + + // create dev server instance + const { server } = await createDevServer( + api, + options, + args, + projectDevServerOptions, + compiler + ) + return new Promise((resolve, reject) => { - webpack(webpackConfigs).watch({}, (err, stats) => { - handleWebpackDone(err, stats, true) + // // handle compiler error + // compiler.hooks.failed.tap('mpx-cli-service serve', (msg) => { + // reject(msg) + // }) + + compiler.hooks.done.tap('vue-cli-service serve', (stats) => { + handleWebpackDone(null, stats, true) .then((...res) => { if (!options.disabledDefaultLinkFile) { symlinkTargetConfig(api, target, webpackConfigs[0]) @@ -20,5 +47,7 @@ module.exports.serveMp = async function serveMp (api, options, args) { }) .catch(reject) }) + + server.start().catch((err) => reject(err)) }) } diff --git a/packages/vue-cli-plugin-mpx/commands/serve/utils.js b/packages/vue-cli-plugin-mpx/commands/serve/utils.js new file mode 100644 index 00000000..e65fa562 --- /dev/null +++ b/packages/vue-cli-plugin-mpx/commands/serve/utils.js @@ -0,0 +1,186 @@ +const WebpackDevServer = require('webpack-dev-server') +const launchEditorMiddleware = require('launch-editor-middleware') + +const defaults = { + host: '0.0.0.0', + port: 8080, + https: false +} + +module.exports.createDevServer = async function (api, options, args, projectDevServerOptions, compiler) { + const portfinder = require('portfinder') + const prepareURLs = require('@vue/cli-service/lib/util/prepareURLs') + const prepareProxy = require('@vue/cli-service/lib/util/prepareProxy') + const isAbsoluteUrl = require('@vue/cli-service/lib/util/isAbsoluteUrl') + + const isInContainer = checkInContainer() + const isProduction = process.env.NODE_ENV === 'production' + + // resolve server options + const protocol = 'http' + const host = process.env.HOST || projectDevServerOptions.host || defaults.host + portfinder.basePort = + process.env.PORT || projectDevServerOptions.port || defaults.port + const port = await portfinder.getPortPromise() + const rawPublicUrl = args.public || projectDevServerOptions.public + const publicUrl = rawPublicUrl + ? /^[a-zA-Z]+:\/\//.test(rawPublicUrl) + ? rawPublicUrl + : `${protocol}://${rawPublicUrl}` + : null + const publicHost = publicUrl + ? /^[a-zA-Z]+:\/\/([^/?#]+)/.exec(publicUrl)[1] + : undefined + + const urls = prepareURLs( + protocol, + host, + port, + isAbsoluteUrl(options.publicPath) ? '/' : options.publicPath + ) + const localUrlForBrowser = publicUrl || urls.localUrlForBrowser + + const proxySettings = prepareProxy( + projectDevServerOptions.proxy, + api.resolve('public') + ) + + // inject dev & hot-reload middleware entries + let webSocketURL + if (!isProduction) { + if (publicHost) { + // explicitly configured via devServer.public + webSocketURL = { + protocol: protocol === 'https' ? 'wss' : 'ws', + hostname: publicHost, + port + } + } else if (isInContainer) { + // can't infer public network url if inside a container + // infer it from the browser instead + webSocketURL = 'auto://0.0.0.0:0/ws' + } else { + // otherwise infer the url from the config + webSocketURL = { + protocol: protocol === 'https' ? 'wss' : 'ws', + hostname: urls.lanUrlForConfig || 'localhost', + port + } + } + } + + // create server + const server = new WebpackDevServer( + Object.assign( + { + historyApiFallback: { + disableDotRule: true, + htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'], + rewrites: genHistoryApiFallbackRewrites( + options.publicPath, + options.pages + ) + }, + hot: !isProduction + }, + projectDevServerOptions, + { + host, + port, + proxy: proxySettings, + + static: { + directory: api.resolve('public'), + publicPath: options.publicPath, + watch: !isProduction, + + ...projectDevServerOptions.static + }, + + client: { + webSocketURL, + + logging: 'none', + overlay: isProduction // TODO disable this + ? false + : { warnings: false, errors: true }, + progress: !process.env.VUE_CLI_TEST, + + ...projectDevServerOptions.client + }, + setupExitSignals: true, + + setupMiddlewares (middlewares, devServer) { + // launch editor support. + // this works with vue-devtools & @vue/cli-overlay + devServer.app.use( + '/__open-in-editor', + launchEditorMiddleware(() => + console.log( + 'To specify an editor, specify the EDITOR env variable or ' + + 'add "editor" field to your Vue project config.\n' + ) + ) + ) + + // allow other plugins to register middlewares, e.g. PWA + // todo: migrate to the new API interface + api.service.devServerConfigFns.forEach((fn) => + fn(devServer.app, devServer) + ) + + if (projectDevServerOptions.setupMiddlewares) { + return projectDevServerOptions.setupMiddlewares( + middlewares, + devServer + ) + } + + return middlewares + }, + headers: { + 'Access-Control-Allow-Origin': '*' + } + } + ), + compiler + ) + + return { + server, + urls, + publicUrl, + publicHost, + localUrlForBrowser, + isInContainer, + protocol + } +} + +function genHistoryApiFallbackRewrites (baseUrl, pages = {}) { + const path = require('path') + const multiPageRewrites = Object.keys(pages) + // sort by length in reversed order to avoid overrides + // eg. 'page11' should appear in front of 'page1' + .sort((a, b) => b.length - a.length) + .map((name) => ({ + from: new RegExp(`^/${name}`), + to: path.posix.join(baseUrl, pages[name].filename || `${name}.html`) + })) + return [ + ...multiPageRewrites, + { from: /./, to: path.posix.join(baseUrl, 'index.html') } + ] +} + +// https://stackoverflow.com/a/20012536 +function checkInContainer () { + if ('CODESANDBOX_SSE' in process.env) { + return true + } + const fs = require('fs') + if (fs.existsSync('/proc/1/cgroup')) { + const content = fs.readFileSync('/proc/1/cgroup', 'utf-8') + return /:\/(lxc|docker|kubepods(\.slice)?)\//.test(content) + } +} diff --git a/packages/vue-cli-plugin-mpx/commands/serve/web.js b/packages/vue-cli-plugin-mpx/commands/serve/web.js index 46a63682..09d2bf68 100644 --- a/packages/vue-cli-plugin-mpx/commands/serve/web.js +++ b/packages/vue-cli-plugin-mpx/commands/serve/web.js @@ -3,28 +3,16 @@ const { getReporter } = require('../../utils/reporter') const { extractResultFromStats } = require('../../utils/output') const { resolveServeWebpackConfigByTarget } = require('../../config') const { getCurrentTarget } = require('@mpxjs/cli-shared-utils/lib') - -const defaults = { - host: '0.0.0.0', - port: 8080, - https: false -} +const { createDevServer } = require('./utils') /** @type {import('@vue/cli-service').ServicePlugin} */ module.exports.serveWeb = async (api, options, 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. - const isInContainer = checkInContainer() const isProduction = process.env.NODE_ENV === 'production' const { chalk } = require('@vue/cli-shared-utils') const webpack = require('webpack') - const WebpackDevServer = require('webpack-dev-server') - const portfinder = require('portfinder') - const prepareURLs = require('@vue/cli-service/lib/util/prepareURLs') - const prepareProxy = require('@vue/cli-service/lib/util/prepareProxy') - const launchEditorMiddleware = require('launch-editor-middleware') - const isAbsoluteUrl = require('@vue/cli-service/lib/util/isAbsoluteUrl') // resolve webpack config const target = getCurrentTarget() @@ -34,140 +22,21 @@ module.exports.serveWeb = async (api, options, args) => { target, args ) - const projectDevServerOptions = webpackConfig.devServer || {} - - // resolve server options - const protocol = 'http' - const host = process.env.HOST || projectDevServerOptions.host || defaults.host - portfinder.basePort = - process.env.PORT || projectDevServerOptions.port || defaults.port - const port = await portfinder.getPortPromise() - const rawPublicUrl = args.public || projectDevServerOptions.public - const publicUrl = rawPublicUrl - ? /^[a-zA-Z]+:\/\//.test(rawPublicUrl) - ? rawPublicUrl - : `${protocol}://${rawPublicUrl}` - : null - const publicHost = publicUrl - ? /^[a-zA-Z]+:\/\/([^/?#]+)/.exec(publicUrl)[1] - : undefined - - const urls = prepareURLs( - protocol, - host, - port, - isAbsoluteUrl(options.publicPath) ? '/' : options.publicPath - ) - const localUrlForBrowser = publicUrl || urls.localUrlForBrowser - - const proxySettings = prepareProxy( - projectDevServerOptions.proxy, - api.resolve('public') - ) - - // inject dev & hot-reload middleware entries - let webSocketURL - if (!isProduction) { - if (publicHost) { - // explicitly configured via devServer.public - webSocketURL = { - protocol: protocol === 'https' ? 'wss' : 'ws', - hostname: publicHost, - port - } - } else if (isInContainer) { - // can't infer public network url if inside a container - // infer it from the browser instead - webSocketURL = 'auto://0.0.0.0:0/ws' - } else { - // otherwise infer the url from the config - webSocketURL = { - protocol: protocol === 'https' ? 'wss' : 'ws', - hostname: urls.lanUrlForConfig || 'localhost', - port - } - } - } - // create compiler const compiler = webpack(webpackConfig) - // create server - const server = new WebpackDevServer( - Object.assign( - { - historyApiFallback: { - disableDotRule: true, - htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'], - rewrites: genHistoryApiFallbackRewrites( - options.publicPath, - options.pages - ) - }, - hot: !isProduction - }, - projectDevServerOptions, - { - host, - port, - proxy: proxySettings, - - static: { - directory: api.resolve('public'), - publicPath: options.publicPath, - watch: !isProduction, - - ...projectDevServerOptions.static - }, - - client: { - webSocketURL, - - logging: 'none', - overlay: isProduction // TODO disable this - ? false - : { warnings: false, errors: true }, - progress: !process.env.VUE_CLI_TEST, - - ...projectDevServerOptions.client - }, - setupExitSignals: true, - - setupMiddlewares (middlewares, devServer) { - // launch editor support. - // this works with vue-devtools & @vue/cli-overlay - devServer.app.use( - '/__open-in-editor', - launchEditorMiddleware(() => - console.log( - 'To specify an editor, specify the EDITOR env variable or ' + - 'add "editor" field to your Vue project config.\n' - ) - ) - ) - - // allow other plugins to register middlewares, e.g. PWA - // todo: migrate to the new API interface - api.service.devServerConfigFns.forEach((fn) => - fn(devServer.app, devServer) - ) - - if (projectDevServerOptions.setupMiddlewares) { - return projectDevServerOptions.setupMiddlewares( - middlewares, - devServer - ) - } + // resolve devServer options + const projectDevServerOptions = webpackConfig.devServer || {} - return middlewares - }, - headers: { - 'Access-Control-Allow-Origin': '*' - } - } - ), - compiler - ) + // create dev server instance + const { + server, + publicUrl, + urls, + localUrlForBrowser, + isInContainer, + protocol + } = await createDevServer(api, options, args, projectDevServerOptions, compiler) return new Promise((resolve, reject) => { // handle compiler error @@ -267,12 +136,15 @@ module.exports.serveWeb = async (api, options, args) => { // signal for test to check HMR logChunk.push('App updated') } - result.push(logChunk.map(v => ` ${v}`).join('\n')) + result.push(logChunk.map((v) => ` ${v}`).join('\n')) } - result.push('', extractResultFromStats(stats, { - assets: false - })) + result.push( + '', + extractResultFromStats(stats, { + assets: false + }) + ) getReporter()._renderStates([ { @@ -288,31 +160,3 @@ module.exports.serveWeb = async (api, options, args) => { server.start().catch((err) => reject(err)) }) } - -// https://stackoverflow.com/a/20012536 -function checkInContainer () { - if ('CODESANDBOX_SSE' in process.env) { - return true - } - const fs = require('fs') - if (fs.existsSync('/proc/1/cgroup')) { - const content = fs.readFileSync('/proc/1/cgroup', 'utf-8') - return /:\/(lxc|docker|kubepods(\.slice)?)\//.test(content) - } -} - -function genHistoryApiFallbackRewrites (baseUrl, pages = {}) { - const path = require('path') - const multiPageRewrites = Object.keys(pages) - // sort by length in reversed order to avoid overrides - // eg. 'page11' should appear in front of 'page1' - .sort((a, b) => b.length - a.length) - .map((name) => ({ - from: new RegExp(`^/${name}`), - to: path.posix.join(baseUrl, pages[name].filename || `${name}.html`) - })) - return [ - ...multiPageRewrites, - { from: /./, to: path.posix.join(baseUrl, 'index.html') } - ] -} diff --git a/packages/vue-cli-plugin-mpx/config/base.js b/packages/vue-cli-plugin-mpx/config/base.js index 526db60d..f74c5bbc 100644 --- a/packages/vue-cli-plugin-mpx/config/base.js +++ b/packages/vue-cli-plugin-mpx/config/base.js @@ -648,4 +648,11 @@ module.exports.addServeWebpackConfig = function ( // https://github.com/vuejs/vue-cli/issues/3539 config.output.globalObject("(typeof self !== 'undefined' ? self : this)") } + if (target.mode !== 'web') { + config.devServer.set('devMiddleware', { + writeToDisk: true + }) + config.devServer.set('webSocketServer', false) + config.devServer.hot(false) + } } diff --git a/packages/vue-cli-plugin-mpx/package.json b/packages/vue-cli-plugin-mpx/package.json index 6731450f..04364c52 100644 --- a/packages/vue-cli-plugin-mpx/package.json +++ b/packages/vue-cli-plugin-mpx/package.json @@ -1,6 +1,6 @@ { "name": "@mpxjs/vue-cli-plugin-mpx", - "version": "2.1.32", + "version": "2.1.33-2", "description": "base mpx plugin for mpx-cli", "keywords": [], "license": "ISC", @@ -10,7 +10,7 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { - "@mpxjs/cli-shared-utils": "^2.1.32", + "@mpxjs/cli-shared-utils": "^2.1.33-2", "@soda/friendly-errors-webpack-plugin": "^1.8.0", "@vue/cli-shared-utils": "^5.0.4", "@vue/vue-loader-v15": "npm:vue-loader@^15.9.7", @@ -29,7 +29,8 @@ "webpackbar": "^5.0.0", "wrap-ansi": "^5.1.0", "consola": "^2.15.3", - "std-env": "^3.0.1" + "std-env": "^3.0.1", + "chokidar": "^4.0.3" }, "devDependencies": { "@babel/core": "^7.12.16", @@ -41,7 +42,7 @@ "@mpxjs/babel-plugin-inject-page-events": "^2.8.0", "@mpxjs/core": "^2.9.69", "@mpxjs/fetch": "^2.9.69", - "@mpxjs/mpx-cli-service": "^2.1.32", + "@mpxjs/mpx-cli-service": "^2.1.33-2", "@mpxjs/pinia": "^2.9.69", "@mpxjs/size-report": "^2.8.0", "@mpxjs/store": "^2.9.69", diff --git a/packages/vue-cli-plugin-mpx/utils/symlink.js b/packages/vue-cli-plugin-mpx/utils/symlink.js index 6c5e7c15..08a711d0 100644 --- a/packages/vue-cli-plugin-mpx/utils/symlink.js +++ b/packages/vue-cli-plugin-mpx/utils/symlink.js @@ -20,8 +20,18 @@ module.exports.symlinkTargetConfig = function (api, target, webpackConfig) { } try { const targetConfigFile = path.resolve(outputPath, v) - if (fs.existsSync(targetConfigFile)) fs.unlinkSync(targetConfigFile) - fs.linkSync(api.resolve(`static/${target.mode}/${v}`), targetConfigFile) + // 监听该文件变动,同步static下 + const chokidar = require('chokidar') + chokidar + .watch(targetConfigFile, { ignoreInitial: true }) + .on('all', (event, path) => { + fs.copyFileSync( + api.resolve(`static/${target.mode}/${v}`), + path.resolve(outputPath, v) + ) + }) + // if (fs.existsSync(targetConfigFile)) fs.unlinkSync(targetConfigFile) + // fs.linkSync(api.resolve(`static/${target.mode}/${v}`), targetConfigFile) } catch (error) { fs.copyFileSync( api.resolve(`static/${target.mode}/${v}`), @@ -39,7 +49,5 @@ module.exports.symlinkTargetConfig = function (api, target, webpackConfig) { ) fs.copyFileSync(targetOutputFile, rnInputFile) } - } catch (error) { - - } + } catch (error) {} } diff --git a/yarn.lock b/yarn.lock index 73831e67..fb0fda3c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5810,6 +5810,13 @@ chokidar@^3.5.3: optionalDependencies: fsevents "~2.3.2" +chokidar@^4.0.3: + version "4.0.3" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-4.0.3.tgz#7be37a4c03c9aee1ecfe862a4a23b2c70c205d30" + integrity sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA== + dependencies: + readdirp "^4.0.1" + chownr@^1.1.1, chownr@^1.1.2, chownr@^1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.4.tgz#6fc9d7b42d32a583596337666e7d08084da2cc6b" @@ -14541,6 +14548,11 @@ readdir-scoped-modules@^1.0.0: graceful-fs "^4.1.2" once "^1.3.0" +readdirp@^4.0.1: + version "4.1.2" + resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-4.1.2.tgz#eb85801435fbf2a7ee58f19e0921b068fc69948d" + integrity sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg== + readdirp@~3.6.0: version "3.6.0" resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7"