From bb84d90cdcd93ffab60a51d6b6ab1a312e633cca Mon Sep 17 00:00:00 2001 From: Dmitry Kuzin Date: Thu, 5 Oct 2023 17:10:41 +0400 Subject: [PATCH] Work for #7084: add i18n dir in 'survey-core' build --- build-scripts/survey-core/webpack.i18n.js | 32 ++++++++++++++++------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/build-scripts/survey-core/webpack.i18n.js b/build-scripts/survey-core/webpack.i18n.js index 2e10585aa9..09812d3542 100644 --- a/build-scripts/survey-core/webpack.i18n.js +++ b/build-scripts/survey-core/webpack.i18n.js @@ -1,5 +1,6 @@ "use strict"; - +const fs = require("fs"); +const path = require("path"); const webpackCommonConfigCreator = require("../webpack.common"); const { merge } = require("webpack-merge"); var packageJson = require("./package.json"); @@ -14,19 +15,30 @@ const config = { } } }; +function patchEntries() { + config.entry = {}; + fs.readdirSync(path.resolve(__dirname, "../../src/localization")).forEach(file => { + var extension = path.extname(file); + if (extension.toLowerCase() === ".ts") { + config.entry[path.basename(file, extension)] = (path.resolve(__dirname, "../../src/localization") + "/" + file); + } + }); + config.entry.index = path.resolve(__dirname, "../../src/entries/i18n.ts"); +} -// fs.readdirSync(path.resolve(__dirname, "../../src/localization")).forEach(file => { -// var extension = path.extname(file); -// if (extension.toLowerCase() === ".ts") { -// config.entry[path.basename(file, extension)] = (path.resolve(__dirname, "../../src/localization") + "\\" + file); -// // console.log(path.basename(file, extension)); -// // console.log(path.resolve(__dirname, "../../src/localization") + "\\" + file); -// } -// }); - +function patchFilename(options) { + config.output = {}; + const isProductionBuild = options.buildType === "prod"; + config.output.filename = (pathData) => { + return (pathData.chunk.name == "survey.i18n" ? "[name]" : "i18n/[name]") + (isProductionBuild ? ".min" : "") + ".js"; + } +} module.exports = function (options) { options.platform = "i18n"; options.libraryName = "SurveyLocales"; + patchEntries(); + patchFilename(options); return merge(webpackCommonConfigCreator(options, packageJson, "survey.i18n"), config); }; +