diff --git a/rsbuild.config.ts b/rsbuild.config.ts index b188d494e57552af370b90122c03e82b5720c2c0..2bf517c00bee0cfec41f408ba699696f8dffdf63 100644 --- a/rsbuild.config.ts +++ b/rsbuild.config.ts @@ -10,14 +10,20 @@ let pageTitle = 'neatlogic'; let login_Title = 'welcome'; let table_style = 'border'; let imgModule = './public/resource'; +let copyPath = ''; +let faviconPath = './public/resource/img/common/tsfavicon.png'; let importCustomConfig = glob.sync(`${commercialModule}/**/customconfig.js`) || []; importCustomConfig.forEach((filePath) => { if (filePath) { - let {tableStyle, title, loginTitle, imgPath} = require(filePath); + let {tableStyle, title, loginTitle, imgPath, publicPath, faviconIconPath} = require(filePath); login_Title = String(loginTitle) || 'welcome'; table_style = String(tableStyle); pageTitle = String(title); imgModule = imgPath; + copyPath = publicPath; + if (faviconIconPath) { + faviconPath = faviconIconPath; + } } }); const resolve = dir => path.resolve(__dirname, dir); @@ -70,12 +76,41 @@ function getPages(pageList) { const pages = getPages(process.env.VUE_APP_PAGE_LIST); let tenantNames = process.env.NODE_ENV === 'development' ? tenantName : ''; const ent = Object.fromEntries(Object.keys(pages).map(key => [tenantNames + '/' + key, pages[key].entry])); - +const copyRsPack = copyPath ? [ + { + from: resolve(copyPath), // 需要复制的目录 + to: resolve('/dist/'), // 复制到目标目录 + force: true, + filter: (resourcePath) => { + // 只复制 .html 文件 + return resourcePath.endsWith('.html'); + }, + noErrorOnMissing: true // 当没有找到对应的文件或目录时,忽略错误 + }, + { + from: resolve(copyPath), + to: resolve('dist/resource/'), + filter: (resourcePath) => { + return !resourcePath.endsWith('.html'); + }, + force: true, + noErrorOnMissing: true + } +] : []; +const copyFavicon = faviconPath ? [ + { + from: resolve(faviconPath), + to: resolve('dist/resource/img/common/'), + force: true, + noErrorOnMissing: true // 忽略文件不存在的错误 + } +] : []; export default defineConfig({ plugins: [pluginVue2()], html: { template: './public/rs-index.html', - title: pageTitle + title: pageTitle, + favicon: faviconPath }, dev: { assetPrefix: '/' @@ -88,7 +123,10 @@ export default defineConfig({ 'GLOBAL_PAGELIST': "''", 'GLOBAL_TABLESTRYLE': JSON.stringify(table_style), 'GLOBAL_LOGINTITLE': JSON.stringify(login_Title) - }) + }), + new rspack.CopyRspackPlugin({ + patterns: [...copyRsPack, ...copyFavicon] + }) ] }, less: { diff --git a/vue.config.js b/vue.config.js index 73e0c7b57afce9845f90777833be5e73e0d85b98..9ddffd70af84a0ce44cb317aced28b9b7d4c478e 100755 --- a/vue.config.js +++ b/vue.config.js @@ -8,15 +8,19 @@ let commercialModule = './src/commercial-module'; let localUrl = '../neatlogic-web/src/resources'; let pageTitle = 'neatlogic'; //页面标题名称 const { tenantName, urlPrefix } = require('./apiconfig.json'); +let faviconIcon = './public/resource/img/common/tsfavicon.png'; let importCustomConfig = glob.sync(`${commercialModule}/**/customconfig.js`) || []; importCustomConfig.forEach((filePath) => { if (filePath) { - let {tableStyle, title, loginTitle, imgPath, publicPath = ''} = require(filePath); + let {tableStyle, title, loginTitle, imgPath, publicPath = '', faviconIconPath} = require(filePath); process.env.VUE_APP_LOGINTITLE = loginTitle || 'welcome'; process.env.VUE_APP_TABLESTRYLE = tableStyle; pageTitle = title; copyPath = publicPath; baseImg = imgPath; + if (faviconIconPath) { + faviconIcon = faviconIconPath; + } } }); function getPages(pageList) { @@ -95,6 +99,34 @@ function getAllModuleList(defaultModuleList, modulePathList = []) { function resolve(dir) { return path.join(__dirname, dir); } +const copyRsPack = copyPath ? [ + { + from: resolve(copyPath), // 需要复制的目录 + to: resolve('dist/'), // 复制到目标目录 + force: true, + filter: (resourcePath) => { + return resourcePath.endsWith('.html'); // 只复制 .html 文件 + }, + noErrorOnMissing: true // 当没有找到对应的文件或目录时,忽略错误 + }, + { + from: resolve(copyPath), + to: resolve('dist/resource/'), + filter: (resourcePath) => { + return !resourcePath.endsWith('.html'); + }, + force: true, + noErrorOnMissing: true + } +] : []; +const copyFavicon = faviconIcon ? [ + { + from: resolve(faviconIcon), + to: resolve('dist/resource/img/common/'), + force: true, + noErrorOnMissing: true + } +] : []; module.exports = { css: { loaderOptions: { @@ -122,27 +154,11 @@ module.exports = { performance: { hints: false }, - plugins: copyPath ? [ + plugins: [ new CopyPlugin({ - patterns: [ - { - from: path.resolve(__dirname, copyPath), // 需要复制的目录 - to: path.resolve(__dirname, 'dist/'), // 复制到目标目录 - filter: (resourcePath) => { - // 只复制 .html 文件 - return resourcePath.endsWith('.html'); - } - }, - { - from: path.resolve(__dirname, copyPath), - to: path.resolve(__dirname, 'dist/resource/'), - filter: (resourcePath) => { - return !resourcePath.endsWith('.html'); - } - } - ] - }) - ] : [] + patterns: [...copyRsPack, ...copyFavicon] + }) + ] }, chainWebpack: config => { config.module.rule('vue').use('vue-path-injector').loader(require.resolve('./vue-path-injector.js')).after('vue-loader').end();