diff --git a/Changelog.md b/Changelog.md index 2cf18ca..7c19c25 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,9 +4,13 @@ This page contains information about changes to the PowerBI Visual Tools (pbiviz ## 5.1.0 * New flag `--skip-api` to skip verifying api version. It might produce different errors in visual, so use it only in some specific cases (ex. installing something during the build process brakes packages managed by monorepo managers). +* New flag `--all-locales` to disable optimization using localization loader. It's recommended not to use this flag because all locales take a huge amount of package size. If you need just a few of them follow [this guide](https://learn.microsoft.com/en-us/power-bi/developer/visuals/localization?tabs=English#step-5---add-a-resources-file-for-each-language). In this case, only declared in stringResources locales will be added to your visual package. ## 5.0.3 * Now option `--install-cert` is command. The new usage is `pbiviz install-cert` **⚠** + +## 5.0.3 +* Now option `--install-cert` is command. New usage is `pbiviz install-cert` * Fixed bug with the incorrect detection of the installed API version ## 5.0.2 diff --git a/bin/pbiviz.js b/bin/pbiviz.js index 9bd1cf3..c271f69 100755 --- a/bin/pbiviz.js +++ b/bin/pbiviz.js @@ -75,6 +75,7 @@ pbiviz .option('-d, --drop', 'Drop outputs into output folder') .option('--no-stats', "Doesn't generate statistics files") .option('--skip-api', "Skips powerbi-visuals-api verifying") + .option('-l, --all-locales', "Keeps all locale files in the package. By default only used inside stringResources folder locales are included.") .action(async (options) => { CommandManager.start(options, rootPath); }); @@ -87,6 +88,7 @@ pbiviz .option('--no-minify', "Doesn't minify the js in the package (useful for debugging)") .option('--no-stats', "Doesn't generate statistics files") .option('--skip-api', "Skips powerbi-visuals-api verifying") + .option('-l, --all-locales', "Keeps all locale files in the package. By default only used inside stringResources folder locales are included.") .addOption(new Option('-c, --compression ', "Enables compression of visual package") .choices(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']) .default('6') diff --git a/spec/e2e/pbivizInfoSpec.js b/spec/e2e/pbivizInfoSpec.js index 6bbf833..3608543 100644 --- a/spec/e2e/pbivizInfoSpec.js +++ b/spec/e2e/pbivizInfoSpec.js @@ -66,7 +66,7 @@ describe("E2E - pbiviz info", () => { expect(error).toBeDefined(); expect(error.status).toBe(1); - expect(error.message).toContain("Error: pbiviz.json not found. You must be in the root of a visual project to run this command"); + expect(error.message).toContain("pbiviz.json not found. You must be in the root of a visual project to run this command"); }); diff --git a/spec/e2e/pbivizPackageSpec.js b/spec/e2e/pbivizPackageSpec.js index 4db61ac..619c995 100644 --- a/spec/e2e/pbivizPackageSpec.js +++ b/spec/e2e/pbivizPackageSpec.js @@ -73,7 +73,7 @@ describe("E2E - pbiviz package", () => { } expect(error).toBeDefined(); expect(error.status).toBe(1); - expect(error.message).toContain("Error: pbiviz.json not found. You must be in the root of a visual project to run this command"); + expect(error.message).toContain("pbiviz.json not found. You must be in the root of a visual project to run this command"); }); it("Should throw error if there is nothing to produce", () => { diff --git a/spec/e2e/pbivizStartSpec.js b/spec/e2e/pbivizStartSpec.js index 3d32441..cc95663 100644 --- a/spec/e2e/pbivizStartSpec.js +++ b/spec/e2e/pbivizStartSpec.js @@ -90,7 +90,7 @@ describe("E2E - pbiviz start", () => { } expect(error).toBeDefined(); expect(error.status).toBe(1); - expect(error.message).toContain("Error: pbiviz.json not found. You must be in the root of a visual project to run this command"); + expect(error.message).toContain("pbiviz.json not found. You must be in the root of a visual project to run this command"); }); it("Should generate statistic files without flags", (done) => { diff --git a/src/CommandManager.ts b/src/CommandManager.ts index 8109a43..15550f1 100644 --- a/src/CommandManager.ts +++ b/src/CommandManager.ts @@ -9,6 +9,7 @@ interface StartOptions { stats: boolean, drop: boolean, skipApi: boolean + allLocales: boolean } interface PackageOptions { @@ -18,6 +19,7 @@ interface PackageOptions { compression: number, stats: boolean, skipApi: boolean + allLocales: boolean } interface NewOptions { @@ -37,7 +39,8 @@ export default class CommandManager { minify: false, devServerPort: options.port, stats: options.stats, - skipApiCheck: options.skipApi + skipApiCheck: options.skipApi, + allLocales: options.allLocales } const visualManager = new VisualManager(rootPath) await visualManager @@ -60,7 +63,8 @@ export default class CommandManager { minify: options.minify, compression: options.compression, stats: options.stats, - skipApiCheck: options.skipApi + skipApiCheck: options.skipApi, + allLocales: options.allLocales } new VisualManager(rootPath) .prepareVisual() diff --git a/src/VisualManager.ts b/src/VisualManager.ts index d65d185..29a373c 100644 --- a/src/VisualManager.ts +++ b/src/VisualManager.ts @@ -63,7 +63,8 @@ export default class VisualManager { if (this.doesPBIVIZExists()) { this.pbivizConfig = readJsonFromVisual(PBIVIZ_FILE, this.basePath); } else { - throw new Error(PBIVIZ_FILE + ' not found. You must be in the root of a visual project to run this command.') + ConsoleWriter.error(PBIVIZ_FILE + ' not found. You must be in the root of a visual project to run this command.') + process.exit(1); } return this; } diff --git a/src/WebPackWrap.ts b/src/WebPackWrap.ts index b18f14f..1870676 100644 --- a/src/WebPackWrap.ts +++ b/src/WebPackWrap.ts @@ -10,7 +10,7 @@ import { exec as processExec } from 'child_process'; import lodashCloneDeep from 'lodash.clonedeep'; import ExtraWatchWebpackPlugin from 'extra-watch-webpack-plugin'; import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; -import { PowerBICustomVisualsWebpackPlugin } from 'powerbi-visuals-webpack-plugin'; +import { PowerBICustomVisualsWebpackPlugin, LocalizationLoader } from 'powerbi-visuals-webpack-plugin'; import ConsoleWriter from './ConsoleWriter.js'; import { resolveCertificate } from "./CertificateTools.js"; import { readJsonFromRoot, readJsonFromVisual } from './utils.js' @@ -33,6 +33,7 @@ export interface WebpackOptions { devServerPort?: number; fast?: boolean; skipApiCheck?: boolean; + allLocales?: boolean; } export default class WebPackWrap { @@ -226,25 +227,30 @@ export default class WebPackWrap { } } - async useLoader({ - fast = false + async configureLoaders({ + fast = false, + includeAllLocales = false }) { - let tsOptions = {}; - if (fast) { - tsOptions = { - transpileOnly: false, - experimentalWatchApi: false - }; - } this.webpackConfig.module.rules.push({ test: /(\.ts)x?$/, use: [ { loader: "ts-loader", - options: tsOptions + options: fast + ? { + transpileOnly: false, + experimentalWatchApi: false + } + : {} } ] }); + if(!includeAllLocales){ + this.webpackConfig.module.rules.push({ + test: /powerbiGlobalizeLocales\.js$/, // path to file with all locales declared in formattingutils + loader: LocalizationLoader + }); + } } async prepareWebPackConfig(visualPackage, options: WebpackOptions, tsconfig) { @@ -260,8 +266,9 @@ export default class WebPackWrap { await this.appendPlugins(options, visualPackage, tsconfig); await this.configureDevServer(visualPackage, options.devServerPort); await this.configureVisualPlugin(options, tsconfig, visualPackage); - await this.useLoader({ - fast: options.fast + await this.configureLoaders({ + fast: options.fast, + includeAllLocales: options.allLocales }); return this.webpackConfig; @@ -289,7 +296,8 @@ export default class WebPackWrap { fast: false, compression: 0, stats: true, - skipApiCheck: false + skipApiCheck: false, + allLocales: false }) { const tsconfig = readJsonFromVisual('tsconfig.json'); this.pbiviz = readJsonFromVisual('pbiviz.json'); diff --git a/src/webpack.config.ts b/src/webpack.config.ts index be1c116..76073c2 100644 --- a/src/webpack.config.ts +++ b/src/webpack.config.ts @@ -1,6 +1,5 @@ import { getRootPath, readJsonFromRoot } from './utils.js'; -import { LocalizationLoader } from "powerbi-visuals-webpack-plugin"; import MiniCssExtractPlugin from "mini-css-extract-plugin"; import TerserPlugin from "terser-webpack-plugin"; import path from "path"; @@ -65,10 +64,6 @@ const webpackConfig = { { test: /\.(woff|ttf|ico|woff2|jpg|jpeg|png|webp|gif|svg|eot)$/i, type: 'asset/inline' - }, - { - test: /powerbiGlobalizeLocales\.js$/, - loader: LocalizationLoader } ] },