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

RDEV-5995 Added minification in webpack #154

Merged
merged 7 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion ViewGenerator/ViewGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<AssemblyTitle>ViewGenerator</AssemblyTitle>
<Product>ViewGenerator</Product>
<Description>Generates .NET View bindings from typescript</Description>
<Version>1.1.44</Version>
<Version>1.2.0</Version>
<PackageId>ViewGenerator</PackageId>
<PackageTags>Library</PackageTags>

Expand Down
2 changes: 1 addition & 1 deletion ViewGenerator/ViewGenerator.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<developmentDependency>true</developmentDependency>
<dependencies>
<dependency id="ViewGeneratorCore" version="1.0.226" />
<dependency id="ViewPacker" version="1.1.5" />
<dependency id="ViewPacker" version="1.2.0" />
</dependencies>
</metadata>
<files>
Expand Down
9 changes: 3 additions & 6 deletions ViewGenerator/build/ViewGenerator.targets
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@
<!-- /// -->
<!-- Webpack related targets, property and item groups -->
<!-- /// -->

<PropertyGroup>
<WP_Mode>development</WP_Mode>
</PropertyGroup>

<PropertyGroup Condition="'$(WP_OptimizeBundle)' == ''">
<WP_OptimizeBundle>false</WP_OptimizeBundle>
</PropertyGroup>
Expand All @@ -74,12 +69,14 @@
</PropertyGroup>

<PropertyGroup Condition="$(Configuration.Split(&quot;_&quot;)[0].StartsWith('Debug'))">
<WP_Mode>development</WP_Mode>
<WP_DevTool>inline-source-map</WP_DevTool>
<WP_UseCache>true</WP_UseCache>
</PropertyGroup>

<PropertyGroup Condition="$(Configuration.Split(&quot;_&quot;)[0].StartsWith('Release'))">
<WP_DevTool>false</WP_DevTool>
<WP_Mode>production</WP_Mode>
<WP_DevTool>source-map</WP_DevTool>
<WP_UseCache>false</WP_UseCache>
</PropertyGroup>

Expand Down
1,794 changes: 1,202 additions & 592 deletions ViewGenerator/tools/package-lock.json

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions ViewGenerator/tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@types/dts-generator": "2.1.10",
"@types/fs-extra": "11.0.3",
"@types/dts-generator": "2.1.11",
"@types/fs-extra": "11.0.4",
"@types/glob": "8.1.0",
"@types/webpack": "5.28.4",
"fork-ts-checker-webpack-plugin": "9.0.0",
"mini-css-extract-plugin": "2.7.6",
"webpack-dev-server": "4.15.1",
"@types/webpack": "5.28.5",
"fork-ts-checker-webpack-plugin": "9.0.2",
"mini-css-extract-plugin": "2.8.1",
"terser-webpack-plugin": "5.3.10",
"webpack-dev-server": "5.0.4",
"webpack-manifest-plugin": "5.0.0"
},
"dependencies": {}
Expand Down
22 changes: 18 additions & 4 deletions ViewGenerator/tools/webpack/Plugins/CommonConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import { sync } from "glob";
import { join, parse, resolve } from "path";
import TerserPlugin from "terser-webpack-plugin";
import Webpack from "webpack";
import { Configuration } from "webpack";
import { WebpackManifestPlugin } from "webpack-manifest-plugin";
Expand All @@ -24,7 +25,7 @@ import SassRuleSet from "../Rules/Sass";
import getTypeScriptRuleSet from "../Rules/TypeScript";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";

let getCommonConfiguration = (cacheName: string, libraryName: string, assemblyName?: string, pluginsRelativePath?: string, forHotReload?: boolean): Configuration => {
let getCommonConfiguration = (isProductionBuild: boolean, cacheName: string, libraryName: string, assemblyName?: string, pluginsRelativePath?: string, forHotReload?: boolean): Configuration => {

const entryMap: Dictionary<string> = {}
const outputMap: Dictionary<string> = {};
Expand Down Expand Up @@ -132,9 +133,22 @@ let getCommonConfiguration = (cacheName: string, libraryName: string, assemblyNa
}),
]
};

if (cacheName) {
Configuration.cache ={

if (isProductionBuild) {
Configuration.optimization = {
minimize: true,
minimizer: [new TerserPlugin({
terserOptions: {
keep_classnames: true,
keep_fnames: false,
toplevel: true,
module: true
}
})]
}

} else if (cacheName) {
Configuration.cache = {
type: 'filesystem',
allowCollectingMemory: true,
name: cacheName
Expand Down
2 changes: 1 addition & 1 deletion ViewGenerator/tools/webpack/Plugins/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function sanitizeCommandLineParam(parameter: string): string {
/*
* Removes data-test-id attribute
* */
export function removeDataTestIdTransformer<T extends TypeScript.Node>(): TypeScript.TransformerFactory<T> {
export function removeDataTestIdTransformer<T extends TypeScript.Node>(): (context: TypeScript.TransformationContext) => (node: T) => TypeScript.Node {
return context => {
const visit: TypeScript.Visitor = node => {
if (TypeScript.isJsxAttribute(node)) {
Expand Down
8 changes: 6 additions & 2 deletions ViewGenerator/tools/webpack/webpack_plugins.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import DtsGeneratorPlugin from "./Plugins/DtsGeneratorPlugin";
import { DtsFileName } from "./Plugins/Resources";
import { getCurrentDirectory, sanitizeCommandLineParam } from "./Plugins/Utils";

const config = (env) => {
const config = (env, argv) => {

const standardConfig: Configuration = getCommonConfiguration(env.useCache === "true" ? "pluginsCache" : "", "Plugins", sanitizeCommandLineParam(env.assemblyName));
const standardConfig: Configuration = getCommonConfiguration(
argv.mode === "production",
env.useCache === "true" ? "pluginsCache" : "",
"Plugins",
sanitizeCommandLineParam(env.assemblyName));

standardConfig.optimization = {
runtimeChunk: {
Expand Down
11 changes: 6 additions & 5 deletions ViewGenerator/tools/webpack/webpack_views.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import getCommonConfiguration from "./Plugins/CommonConfiguration";
import { Dictionary, sanitizeCommandLineParam } from "./Plugins/Utils";
import { FullHashPlaceholder, IdPlaceholder, OutputDirectoryDefault, RuntimePlaceholder } from "./Plugins/Resources";

const config = (env) => {
const config = (env, argv) => {

let aliasMap: Dictionary<string> = {};
let externalsMap: Dictionary<string> = {};
Expand Down Expand Up @@ -39,20 +39,21 @@ const config = (env) => {
const sanitizedPluginsRelativePath: string = sanitizeCommandLineParam(env.pluginsRelativePath);

const standardConfig: Configuration = getCommonConfiguration(
env.useCache === "true" ? "viewsCache" : "",
argv.mode === "production",
env.useCache === "true" ? "viewsCache" : "",
"Views",
sanitizeCommandLineParam(env.assemblyName),
sanitizedPluginsRelativePath,
sanitizedPluginsRelativePath,
env.forHotReload === "true");

if (!standardConfig.optimization) {
standardConfig.optimization = {};
}

standardConfig.optimization.runtimeChunk = {
name: "ViewsRuntime"
name: "ViewsRuntime"
};

if (env.optimizeBundle === "true") {
// SplitChunksOptions
standardConfig.optimization.splitChunks = {
Expand Down
2 changes: 1 addition & 1 deletion ViewPacker/ViewPacker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<AssemblyTitle>ViewPacker</AssemblyTitle>
<Product>ViewPacker</Product>
<Description>Creates bundles for view files using webpack</Description>
<Version>1.1.5</Version>
<Version>1.2.0</Version>
<PackageId>ViewPacker</PackageId>
<PackageTags>Library</PackageTags>

Expand Down
Loading
Loading