Skip to content

Commit afc5417

Browse files
committed
Added no-bundle-suffix option for JavaScript files
1 parent 2c4347e commit afc5417

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

MiniWebCompiler.sln

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27130.2020
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.4.33213.308
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniWebCompiler", "MiniWebCompiler\MiniWebCompiler.csproj", "{1E0506AB-06EF-4CCB-8C73-8946A1E724E0}"
77
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Projektmappenelemente", "Projektmappenelemente", "{0BCB2656-6870-41CB-933B-CC77C31A2C59}"
9+
ProjectSection(SolutionItems) = preProject
10+
README.md = README.md
11+
EndProjectSection
12+
EndProject
813
Global
914
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1015
Debug|Any CPU = Debug|Any CPU

MiniWebCompiler/ViewModels/ProjectFile.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,20 @@ private async Task CompileJavaScript(bool force)
435435
Directory.CreateDirectory(Path.Combine(fileDir, buildDir));
436436
}
437437
}
438+
match = Regex.Match(line, @"^\s*/\*\s*no-bundle-suffix\s*\*/", RegexOptions.IgnoreCase);
439+
if (match.Success)
440+
{
441+
bundleFileName = Regex.Replace(bundleFileName, @"\.bundle\.js$", ".js");
442+
}
438443
}
439444
}
445+
bool restoredBundleSuffix = false;
446+
if (bundleFileName == srcFileName)
447+
{
448+
// no-bundle-suffix without the build-dir option: this would overwrite the source file
449+
bundleFileName = Regex.Replace(bundleFileName, @"\.js$", ".bundle.js");
450+
restoredBundleSuffix = true;
451+
}
440452
fullOutputFileName = minFileName;
441453

442454
if (!force && AreFilesUpToDate(minFileName, minFileName + ".map"))
@@ -450,6 +462,10 @@ private async Task CompileJavaScript(bool force)
450462
SaveResultFileTime(minFileName);
451463
SaveResultFileTime(minFileName + ".map");
452464
LastLog = "";
465+
if (restoredBundleSuffix)
466+
{
467+
LastLog += "Warning: Not removing .bundle.js suffix because it would overwrite the source file." + Environment.NewLine + Environment.NewLine;
468+
}
453469

454470
if (AdditionalSourceFiles.Any())
455471
{

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ All these tools are included in the setup package. They are installed locally in
2727

2828
JavaScript configuration
2929
------------------------
30-
JavaScript files are run through `rollup` to bundle them into a single file, if any imports of other files are detected in the source file. The bundled code is wrapped into an immediately invoked function expression (IIFE). The parameters of that function and the arguments when calling it can be specified with comment lines like `/* iife-params($) */` and `/* iife-args(jQuery) */` near the top of the file. The code between the parentheses is inserted into the generated file. The comment `/* no-iife */` disables the use of an IIFE and basically concatenates all the files together.
30+
JavaScript files are run through `rollup` to bundle them into a single file, if any imports of other files are detected in the source file. The bundled code is wrapped into an immediately invoked function expression (IIFE). The parameters of that function and the arguments when calling it can be specified with comment lines like `/* iife-params($) */` and `/* iife-args(jQuery) */` near the top of the file. The code between the parentheses is inserted into the generated file. The comment `/* no-iife */` disables the use of an IIFE and basically concatenates all the files together. The comment `/* no-bundle-suffix */` avoids adding the ".bundle.js" suffix to the bundled file name. This is only effective when a different build output directory is specified (see below).
3131

3232
JavaScript mangling by `uglify-js` can be configured with the following comments: `/* no-mangle */` disables mangling completely (nothing is renamed), `/* keep-fnames */` disables renaming functions, `/* keep-fargs */` disables renaming function arguments (parameter names). These options can be used together with the “Unminify” command to debug compressing or mangling errors in your JavaScript code. It will take the .min.js file and beautify it into a .unmin.js file in the same (output) directory.
3333

0 commit comments

Comments
 (0)