Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented flag to disable localization loader #477

Merged
merged 23 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions bin/pbiviz.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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 <compressionLevel>', "Enables compression of visual package")
.choices(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
.default('6')
Expand Down
2 changes: 1 addition & 1 deletion spec/e2e/pbivizInfoSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

});

Expand Down
2 changes: 1 addition & 1 deletion spec/e2e/pbivizPackageSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion spec/e2e/pbivizStartSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
8 changes: 6 additions & 2 deletions src/CommandManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface StartOptions {
stats: boolean,
drop: boolean,
skipApi: boolean
allLocales: boolean
}

interface PackageOptions {
Expand All @@ -18,6 +19,7 @@ interface PackageOptions {
compression: number,
stats: boolean,
skipApi: boolean
allLocales: boolean
}

interface NewOptions {
Expand All @@ -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
Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/VisualManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
36 changes: 22 additions & 14 deletions src/WebPackWrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -33,6 +33,7 @@ export interface WebpackOptions {
devServerPort?: number;
fast?: boolean;
skipApiCheck?: boolean;
allLocales?: boolean;
}

export default class WebPackWrap {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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');
Expand Down
5 changes: 0 additions & 5 deletions src/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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
}
]
},
Expand Down