GitBucket
4.6.0
Toggle navigation
Sign in
Files
Branches
1
Tags
Issues
Pull Requests
Labels
Milestones
Wiki
08335
/
hivui-platform-template
hivui平台项目模板
Browse code
@中文描述: 编译全部时,一起打包语言包文件
@版本: 1.1.38 @升级登记:1 @同步后端:0 @同步数据库:0 @同步配置:0 @向下兼容:1
master
1 parent
17037a7
commit
3b9ee36f81f89a9067b77fa61cc01af5d5bafb76
caibinghong
authored
on 19 Apr 2023
Showing
2 changed files
build/webpack.get-list.js
package.json
Ignore Space
Show notes
View
build/webpack.get-list.js
var fsextra = require('fs-extra'); const path = require("path"); const glob = require('glob') // const fs = require("fs"); // const {Chalk} = require('chalk') const merge = require('webpack-merge'); const webpack = require('webpack'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const CleanWebpackPlugin = require('clean-webpack-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const baseWebpackConfig = require('./webpack.base.conf'); const packageConfig = require('../package.json'); const projectName = packageConfig.name == 'hi-vui-template' ? 'project' : packageConfig.name // console.log('---------------------webpack.get-list.js------------', process.env.NODE_ENV) function repeat(array) { let map = new Map(); let array1 = []; // 数组用于返回结果 for (let i = 0, leng = array.length; i < leng; i++) { if (map.has(array[i])) { // 判断是否存在key map.set(array[i], true); } else { map.set(array[i], false); array1.push(array[i]); } } return array1; } // 用来记录当前打包的模块路径列表,判断进程参数 let argvs = (process.argv[2] || "").replace(/\s*$/g, "") let moduleList = []; let isBuildAll = true; if (argvs) { isBuildAll = false; moduleList = []; let list = argvs.split(','); for (let i = 0, l = list.length; i < l; i++) { // let checkPath = fs.existsSync(list[i]+'/package.json'); //如果目录存在 返回 true ,如果目录不存在 返回false // if (checkPath == false) continue; let modulePath = list[i]; let pathList = glob.sync(modulePath + '/package.json'); // 这个执行比较快 114.811ms if (pathList.length == 0) { // 查找modulePath目录 // let ls = glob.sync(`${modulePath}/!(dist|node_modules|build)/**/package.json`) // for (let k = 0, l = ls.length; k < l; k++) { // moduleList.push(ls[k].replace('/package.json', '')); // } if (modulePath == './assets_platform' || modulePath == './error') { let res = modulePath.replace('./', ''); var isexist = fsextra.existsSync(path.resolve(__dirname, '../', res)); isexist && fsextra.copySync(path.resolve(__dirname, '../', res), path.resolve(__dirname, '../dist/', res), { overwrite: false, // errorOnExist:false }) //拷贝模块资源目录 } else if (/\/deploy\/desktop\/[\w,\/,\.]*\/dpdst\/[\w,\/,\.]*(\.dpdst)$/.test(modulePath)) { //服务部署环境配置的.json let buildScheme = fsextra.readJsonSync(path.resolve(__dirname, '../', modulePath.replace('.dpdst', '.json'))); let settingPath = path.resolve(__dirname, '../dist/', projectName + '/setting/desktop/appsetting.js'); if (buildScheme.appSetting == null) { console.log('build_error:部署环境文件没有绑定,无法同步appSetting!'); break; } fsextra.copySync(path.resolve(__dirname, '../', buildScheme.appSetting), settingPath, { overwrite: false, // errorOnExist:false }) //拷贝模块资源目录 } else { // if(/(\/res)$/.test(modulePath)) let res = modulePath.replace('./', ''); var isexist = fsextra.existsSync(path.resolve(__dirname, '../', res)); isexist && fsextra.copySync(path.resolve(__dirname, '../', res), path.resolve(__dirname, '../dist/', res), { overwrite: false, // errorOnExist:false }) //拷贝模块资源目录 } continue } else { moduleList.push(modulePath); } } } else { //编译所有,找出模块 moduleList = require('./webpack.get-module').moduleList || []; //拷贝模块资源目录 let res = './assets_platform'.replace('./', ''); let isexist = fsextra.existsSync(path.resolve(__dirname, '../', res)); isexist && fsextra.copySync(path.resolve(__dirname, '../', res), path.resolve(__dirname, '../dist/', res), { overwrite: false, // errorOnExist:false }) res = `./${projectName}/lang`.replace('./', ''); isexist = fsextra.existsSync(path.resolve(__dirname, '../', res)); isexist && fsextra.copySync(path.resolve(__dirname, '../', res), path.resolve(__dirname, '../dist/', res), { overwrite: false, // errorOnExist:false }) } moduleList = repeat(moduleList); //去重 let evnConfig = require('./getEnvVar') let webpackList = [], resList = []; //构建webpack 配置 for (let i = 0, l = moduleList.length; i < l; i++) { let MODULE = moduleList[i]; // console.log('---------------模块-------------',MODULE) if (isBuildAll) { //全部编译时拷资源文件res let res = MODULE.indexOf('/view') > -1 ? MODULE.split('view')[0] + 'res' : ''; // console.log('=========================',res) if (res) { res = res.replace('./', ''); var isexist = fsextra.existsSync(path.resolve(__dirname, '..', res)); if (isexist) { // console.log('拷贝模块资源目录====',path.resolve(__dirname, '..', res)) fsextra.copySync(path.resolve(__dirname, '..', res), path.resolve(__dirname, '../dist', res), { overwrite: false, // errorOnExist:false }) //拷贝模块资源目录 } } } // continue; //添加每个模块的webpack 配置 let MODULE_NAME = MODULE.split('/').pop(); let entry = {}; let outputPath = path.resolve(__dirname, '../dist', MODULE) entry[MODULE_NAME] = ['babel-polyfill', `${MODULE}/index.js`]; // @babel/polyfill let wpk = merge({ mode: 'production', // mode: 'development', // devtool: 'source-map', }, baseWebpackConfig, { entry: entry, output: { path: outputPath, filename: `static/js/[name].js`, // publicPath:'./' // publicPath: `/${evnConfig.VITE_APP_SERVER.replace(/"/gi,"")}/render/${packageConfig.author}/${MODULE.replace('./', '')}/` publicPath: `${evnConfig.VITE_APP_USERPATH.replace(/"/gi,"")}/${MODULE.replace('./', '')}/` } }); let htmlTemplate = `${MODULE}/index.html` // var checkPath = fs.existsSync(htmlTemplate); // //如果目录存在 返回 true ,如果目录不存在 返回false // if (checkPath == false) { // htmlTemplate = path.resolve(__dirname, './template.html') // } let pathList = glob.sync(htmlTemplate); // 这个执行比较快 114.811ms if (pathList.length == 0) htmlTemplate = path.resolve(__dirname, './template.html'); wpk.plugins.push(new CleanWebpackPlugin([outputPath], { root: path.resolve(__dirname, '../'), //根目录 //其他配置按需求添加 verbose: false, //不提示删除 })); wpk.plugins.push( new MiniCssExtractPlugin({ filename: 'static/css/[name].[contenthash].css', chunkFilename: `static/css/[name].[contenthash].css` }) ); wpk.plugins.push( new HtmlWebpackPlugin({ filename: path.resolve(__dirname, '../dist', MODULE, 'index.html'), template: htmlTemplate, //如果html 不存在考虑用全局根目录下 inject: true, minify: { removeComments: true, //去除注释 collapseWhitespace: true, //是否去除空格 removeAttributeQuotes: true //去除空属性 }, compile: true })) var isexist = fsextra.existsSync(path.resolve(__dirname, '../', MODULE, 'lang')); if (isexist) { wpk.plugins.push( new CopyWebpackPlugin([{ from: path.resolve(__dirname, '../', MODULE, 'lang'), to: path.resolve(__dirname, '../dist/', MODULE, 'lang'), }]) ) } webpackList.push(wpk); } module.exports = webpackList; // [webpackList[4]] ////[webpackList[3]];//27
var fsextra = require('fs-extra'); const path = require("path"); const glob = require('glob') // const fs = require("fs"); // const {Chalk} = require('chalk') const merge = require('webpack-merge'); const webpack = require('webpack'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const CleanWebpackPlugin = require('clean-webpack-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const baseWebpackConfig = require('./webpack.base.conf'); const packageConfig = require('../package.json'); const projectName = packageConfig.name == 'hi-vui-template' ? 'project' : packageConfig.name // console.log('---------------------webpack.get-list.js------------', process.env.NODE_ENV) function repeat(array) { let map = new Map(); let array1 = []; // 数组用于返回结果 for (let i = 0, leng = array.length; i < leng; i++) { if (map.has(array[i])) { // 判断是否存在key map.set(array[i], true); } else { map.set(array[i], false); array1.push(array[i]); } } return array1; } // 用来记录当前打包的模块路径列表,判断进程参数 let argvs = (process.argv[2] || "").replace(/\s*$/g, "") let moduleList = []; let isBuildAll = true; if (argvs) { isBuildAll = false; moduleList = []; let list = argvs.split(','); for (let i = 0, l = list.length; i < l; i++) { // let checkPath = fs.existsSync(list[i]+'/package.json'); //如果目录存在 返回 true ,如果目录不存在 返回false // if (checkPath == false) continue; let modulePath = list[i]; let pathList = glob.sync(modulePath + '/package.json'); // 这个执行比较快 114.811ms if (pathList.length == 0) { // 查找modulePath目录 // let ls = glob.sync(`${modulePath}/!(dist|node_modules|build)/**/package.json`) // for (let k = 0, l = ls.length; k < l; k++) { // moduleList.push(ls[k].replace('/package.json', '')); // } if (modulePath == './assets_platform' || modulePath == './error') { let res = modulePath.replace('./', ''); var isexist = fsextra.existsSync(path.resolve(__dirname, '../', res)); isexist && fsextra.copySync(path.resolve(__dirname, '../', res), path.resolve(__dirname, '../dist/', res), { overwrite: false, // errorOnExist:false }) //拷贝模块资源目录 } else if (/\/deploy\/desktop\/[\w,\/,\.]*\/dpdst\/[\w,\/,\.]*(\.dpdst)$/.test(modulePath)) { //服务部署环境配置的.json let buildScheme = fsextra.readJsonSync(path.resolve(__dirname, '../', modulePath.replace('.dpdst', '.json'))); let settingPath = path.resolve(__dirname, '../dist/', projectName + '/setting/desktop/appsetting.js'); if (buildScheme.appSetting == null) { console.log('build_error:部署环境文件没有绑定,无法同步appSetting!'); break; } fsextra.copySync(path.resolve(__dirname, '../', buildScheme.appSetting), settingPath, { overwrite: false, // errorOnExist:false }) //拷贝模块资源目录 } else { // if(/(\/res)$/.test(modulePath)) let res = modulePath.replace('./', ''); var isexist = fsextra.existsSync(path.resolve(__dirname, '../', res)); isexist && fsextra.copySync(path.resolve(__dirname, '../', res), path.resolve(__dirname, '../dist/', res), { overwrite: false, // errorOnExist:false }) //拷贝模块资源目录 } continue } else { moduleList.push(modulePath); } } } else { //编译所有,找出模块 moduleList = require('./webpack.get-module').moduleList || []; } moduleList = repeat(moduleList); //去重 let evnConfig = require('./getEnvVar') let webpackList = [], resList = []; //构建webpack 配置 for (let i = 0, l = moduleList.length; i < l; i++) { let MODULE = moduleList[i]; // console.log('---------------模块-------------',MODULE) if (isBuildAll) { //全部编译时拷资源文件res let res = MODULE.indexOf('/view') > -1 ? MODULE.split('view')[0] + 'res' : ''; // console.log('=========================',res) if (res) { res = res.replace('./', ''); var isexist = fsextra.existsSync(path.resolve(__dirname, '..', res)); if (isexist) { // console.log('拷贝模块资源目录====',path.resolve(__dirname, '..', res)) fsextra.copySync(path.resolve(__dirname, '..', res), path.resolve(__dirname, '../dist', res), { overwrite: false, // errorOnExist:false }) //拷贝模块资源目录 } } } // continue; //添加每个模块的webpack 配置 let MODULE_NAME = MODULE.split('/').pop(); let entry = {}; let outputPath = path.resolve(__dirname, '../dist', MODULE) entry[MODULE_NAME] = ['babel-polyfill', `${MODULE}/index.js`]; // @babel/polyfill let wpk = merge({ mode: 'production', // mode: 'development', // devtool: 'source-map', }, baseWebpackConfig, { entry: entry, output: { path: outputPath, filename: `static/js/[name].js`, // publicPath:'./' // publicPath: `/${evnConfig.VITE_APP_SERVER.replace(/"/gi,"")}/render/${packageConfig.author}/${MODULE.replace('./', '')}/` publicPath: `${evnConfig.VITE_APP_USERPATH.replace(/"/gi,"")}/${MODULE.replace('./', '')}/` } }); let htmlTemplate = `${MODULE}/index.html` // var checkPath = fs.existsSync(htmlTemplate); // //如果目录存在 返回 true ,如果目录不存在 返回false // if (checkPath == false) { // htmlTemplate = path.resolve(__dirname, './template.html') // } let pathList = glob.sync(htmlTemplate); // 这个执行比较快 114.811ms if (pathList.length == 0) htmlTemplate = path.resolve(__dirname, './template.html'); wpk.plugins.push(new CleanWebpackPlugin([outputPath], { root: path.resolve(__dirname, '../'), //根目录 //其他配置按需求添加 verbose: false, //不提示删除 })); wpk.plugins.push( new MiniCssExtractPlugin({ filename: 'static/css/[name].[contenthash].css', chunkFilename: `static/css/[name].[contenthash].css` }) ); wpk.plugins.push( new HtmlWebpackPlugin({ filename: path.resolve(__dirname, '../dist', MODULE, 'index.html'), template: htmlTemplate, //如果html 不存在考虑用全局根目录下 inject: true, minify: { removeComments: true, //去除注释 collapseWhitespace: true, //是否去除空格 removeAttributeQuotes: true //去除空属性 }, compile: true })) var isexist = fsextra.existsSync(path.resolve(__dirname, '../', MODULE, 'lang')); if (isexist) { wpk.plugins.push( new CopyWebpackPlugin([{ from: path.resolve(__dirname, '../', MODULE, 'lang'), to: path.resolve(__dirname, '../dist/', MODULE, 'lang'), }]) ) } webpackList.push(wpk); } module.exports = webpackList; // [webpackList[4]] ////[webpackList[3]];//27
Ignore Space
Show notes
View
package.json
{ "name": "hi-vui-template", "version": "1.1.38", "description": "A hi-vui-template project", "author": "zhcTeam", "scripts": { "rm:vite": "rimraf node_modules/.vite && rimraf node_modules/.cache", "pm2:start": "pm2 -s start processes.json", "dev": "vite --host", "def": "vite --host", "build": "node build/copyBaseAssets.js && cross-env NODE_ENV=production node build/webpack.prod.conf.js", "build:modules": "cross-env NODE_ENV=production node build/webpack.prod.conf.js", "build1": "webpack --mode production --config build/webpack.prod.conf.js", "dll": "webpack --config build/webpack.dll.conf.js", "start": "webpack-dev-server --config build/webpack.dev.conf.js", "copyassets": "node build/copyBaseAssets.js" }, "devDependencies": { "@babel/core": "^7.1.2", "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7", "@babel/plugin-proposal-optional-chaining": "^7.16.7", "@babel/plugin-syntax-dynamic-import": "^7.0.0", "@babel/preset-env": "^7.1.0", "@vitejs/plugin-vue-jsx": "^1.3.3", "@vue/babel-helper-vue-jsx-merge-props": "^1.2.1", "@vue/babel-preset-jsx": "^1.2.4", "add-asset-html-webpack-plugin": "^3.2.0", "autoprefixer": "^9.1.5", "babel-loader": "^8.0.4", "babel-plugin-component": "^1.1.1", "babel-plugin-transform-vite-meta-env": "^1.0.3", "caniuse-lite": "^1.0.30001436", "chalk": "^3.0.0", "clean-webpack-plugin": "^0.1.19", "copy-webpack-plugin": "^4.5.3", "cross-env": "^7.0.3", "css-loader": "^1.0.0", "dotenv": "^10.0.0", "file-loader": "^2.0.0", "happypack": "^5.0.1", "html-webpack-plugin": "^4.5.2", "less": "^3.13.1", "less-loader": "^5.0.0", "mini-css-extract-plugin": "^1.6.2", "node-sass": "^4.9.3", "optimize-css-assets-webpack-plugin": "^5.0.1", "parallel-webpack": "^2.6.0", "postcss-import": "^11.1.0", "postcss-loader": "^2.1.6", "postcss-url": "^7.3.2", "progress-bar-webpack-plugin": "^2.1.0", "sass": "^1.49.0", "sass-loader": "^7.1.0", "style-loader": "^0.23.0", "terser-webpack-plugin": "^4.2.3", "thread-loader": "^3.0.4", "uglifyjs-webpack-plugin": "^2.0.1", "url-loader": "^1.1.1", "vite": "^2.9.15", "vite-plugin-html": "^2.1.1", "vite-plugin-imp": "^2.0.11", "vite-plugin-pagedata": "^1.0.4", "vite-plugin-vue2": "^1.9.0", "vue-loader": "^15.4.2", "vue-template-compiler": "2.6.14", "webpack": "^4.46.0", "webpack-cli": "^4.9.2", "webpack-dev-server": "^3.11.3", "webpack-merge": "^4.1.4" }, "dependencies": { "axios": "^0.24.0", "babel-polyfill": "^6.26.0", "canvas": "^2.9.0", "classnames": "^2.3.1", "deep-lu-trans": "^1.0.5", "echarts": "^5.2.2", "echarts-liquidfill": "^3.1.0", "element-ui": "^2.15.7", "enquire.js": "^2.1.6", "font-awesome": "^4.7.0", "hi-taskcenter": "^1.0.9", "hi-ui": "^1.1.1006", "html2canvas": "^1.4.1", "jquery": "^3.6.0", "js-cookie": "^3.0.1", "js-md5": "^0.7.3", "js-pinyin": "^0.1.9", "jspdf": "^2.5.1", "lodash": "^4.17.11", "qrcodejs2": "0.0.2", "screenfull": "^6.0.0", "sortablejs": "^1.14.0", "v-clipboard": "^2.2.3", "vue": "2.6.14", "vue-draggable-resizable": "^2.3.0", "vue-gemini-scrollbar": "^2.0.1", "vue-jstree": "^2.1.6", "vue-qr": "^3.2.4", "vue-router": "3.3.4", "vuex": "3.6.2", "xlsx": "^0.18.5", "zhc-birt-cmps": "^2.9.31", "zhc-birt-core": "^1.9.0", "zhc-flowchart": "^1.0.20", "zhc-visualstudio": "^1.0.4" } }
{ "name": "hi-vui-template", "version": "1.1.37", "description": "A hi-vui-template project", "author": "zhcTeam", "scripts": { "rm:vite": "rimraf node_modules/.vite && rimraf node_modules/.cache", "pm2:start": "pm2 -s start processes.json", "dev": "vite --host", "def": "vite --host", "build": "node build/copyBaseAssets.js && cross-env NODE_ENV=production node build/webpack.prod.conf.js", "build:modules": "cross-env NODE_ENV=production node build/webpack.prod.conf.js", "build1": "webpack --mode production --config build/webpack.prod.conf.js", "dll": "webpack --config build/webpack.dll.conf.js", "start": "webpack-dev-server --config build/webpack.dev.conf.js", "copyassets": "node build/copyBaseAssets.js" }, "devDependencies": { "@babel/core": "^7.1.2", "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7", "@babel/plugin-proposal-optional-chaining": "^7.16.7", "@babel/plugin-syntax-dynamic-import": "^7.0.0", "@babel/preset-env": "^7.1.0", "@vitejs/plugin-vue-jsx": "^1.3.3", "@vue/babel-helper-vue-jsx-merge-props": "^1.2.1", "@vue/babel-preset-jsx": "^1.2.4", "add-asset-html-webpack-plugin": "^3.2.0", "autoprefixer": "^9.1.5", "babel-loader": "^8.0.4", "babel-plugin-component": "^1.1.1", "babel-plugin-transform-vite-meta-env": "^1.0.3", "caniuse-lite": "^1.0.30001436", "chalk": "^3.0.0", "clean-webpack-plugin": "^0.1.19", "copy-webpack-plugin": "^4.5.3", "cross-env": "^7.0.3", "css-loader": "^1.0.0", "dotenv": "^10.0.0", "file-loader": "^2.0.0", "happypack": "^5.0.1", "html-webpack-plugin": "^4.5.2", "less": "^3.13.1", "less-loader": "^5.0.0", "mini-css-extract-plugin": "^1.6.2", "node-sass": "^4.9.3", "optimize-css-assets-webpack-plugin": "^5.0.1", "parallel-webpack": "^2.6.0", "postcss-import": "^11.1.0", "postcss-loader": "^2.1.6", "postcss-url": "^7.3.2", "progress-bar-webpack-plugin": "^2.1.0", "sass": "^1.49.0", "sass-loader": "^7.1.0", "style-loader": "^0.23.0", "terser-webpack-plugin": "^4.2.3", "thread-loader": "^3.0.4", "uglifyjs-webpack-plugin": "^2.0.1", "url-loader": "^1.1.1", "vite": "^2.9.15", "vite-plugin-html": "^2.1.1", "vite-plugin-imp": "^2.0.11", "vite-plugin-pagedata": "^1.0.4", "vite-plugin-vue2": "^1.9.0", "vue-loader": "^15.4.2", "vue-template-compiler": "2.6.14", "webpack": "^4.46.0", "webpack-cli": "^4.9.2", "webpack-dev-server": "^3.11.3", "webpack-merge": "^4.1.4" }, "dependencies": { "axios": "^0.24.0", "babel-polyfill": "^6.26.0", "canvas": "^2.9.0", "classnames": "^2.3.1", "deep-lu-trans": "^1.0.5", "echarts": "^5.2.2", "echarts-liquidfill": "^3.1.0", "element-ui": "^2.15.7", "enquire.js": "^2.1.6", "font-awesome": "^4.7.0", "hi-taskcenter": "^1.0.9", "hi-ui": "^1.1.1006", "html2canvas": "^1.4.1", "jquery": "^3.6.0", "js-cookie": "^3.0.1", "js-md5": "^0.7.3", "js-pinyin": "^0.1.9", "jspdf": "^2.5.1", "lodash": "^4.17.11", "qrcodejs2": "0.0.2", "screenfull": "^6.0.0", "sortablejs": "^1.14.0", "v-clipboard": "^2.2.3", "vue": "2.6.14", "vue-draggable-resizable": "^2.3.0", "vue-gemini-scrollbar": "^2.0.1", "vue-jstree": "^2.1.6", "vue-qr": "^3.2.4", "vue-router": "3.3.4", "vuex": "3.6.2", "xlsx": "^0.18.5", "zhc-birt-cmps": "^2.9.31", "zhc-birt-core": "^1.9.0", "zhc-flowchart": "^1.0.20", "zhc-visualstudio": "^1.0.4" } }
Show line notes below