Skip to content

Commit

Permalink
Work for #7084: add i18n dir in 'survey-core' build
Browse files Browse the repository at this point in the history
  • Loading branch information
dk981234 committed Oct 5, 2023
1 parent 6ecdce2 commit bb84d90
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions build-scripts/survey-core/webpack.i18n.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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);
};

0 comments on commit bb84d90

Please sign in to comment.