Skip to content

Commit

Permalink
Merge pull request #235 from OctopusDeploy/john/minify
Browse files Browse the repository at this point in the history
  • Loading branch information
John Simons authored Apr 1, 2022
2 parents a438d77 + d968002 commit 253c329
Show file tree
Hide file tree
Showing 4 changed files with 335 additions and 501 deletions.
16 changes: 14 additions & 2 deletions esbuild.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { build } from "esbuild";
import { cleanPlugin } from "esbuild-clean-plugin";
import { esbuildPluginNodeExternals } from "esbuild-plugin-node-externals";
import copyStaticFiles from "esbuild-copy-static-files";
import glob from "glob";
import { sep } from "path";
Expand Down Expand Up @@ -54,13 +53,26 @@ function noFolders(src) {
return !isDirectory;
}

const bundleAsMuchAsWeCan = {
name: 'my-special-bundle',
setup(build) {
build.onResolve( { filter: /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/ } , args => {
console.log(args.path);
console.log(`args.resolveDir=${args.resolveDir}`);
if(args.path.startsWith("azure-pipelines-tool-lib") || args.path.startsWith( "azure-pipelines-task-lib"))
return { path: args.path, external: true };
})
},
}

build({
entryPoints: entryPoints(),
bundle: true,
target: "es2018",
platform: "node",
outdir: "dist",
metafile: true,
minify: true,
plugins: [
cleanPlugin(),
copyStaticFiles({ src: "./source/img", dest: "dist/img" }),
Expand All @@ -69,7 +81,7 @@ build({
copyStaticFiles({ src: "./node_modules/vss-web-extension-sdk/lib", dest: "dist/widgets/ProjectStatus/lib" }),
copyStaticFiles({ src: "./source/tasks", dest: "dist/tasks", filter: noTSFiles }),
copyStaticFiles({ src: "./source/tasksLegacy", dest: "dist/tasks", filter: noTSFiles }),
esbuildPluginNodeExternals(),
bundleAsMuchAsWeCan
],
logLimit: 0,
logLevel: "info",
Expand Down
11 changes: 7 additions & 4 deletions pack.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,25 @@ function UpdateTaskManifests($workingDirectory, $version, $envName) {
}

function SetupTaskDependencies($workingDirectory) {
& npm prune --production
$tempPath = "$basePath/modules";

mkdir "$tempPath/node_modules"
& npm install --prefix $tempPath azure-pipelines-task-lib azure-pipelines-tool-lib
& npm dedup --prefix $tempPath
& go install github.com/tj/node-prune@latest

$goPath = go env GOPATH
$command = "$goPath/bin/node-prune"

Invoke-Expression "$command ./node_modules"
Invoke-Expression "$command $tempPath/node_modules"

$taskManifestFiles = Get-ChildItem $workingDirectory -Include "task.json" -Recurse

foreach ($manifestFile in $taskManifestFiles) {
$directory = Split-Path -parent $manifestFile

mkdir "$directory/node_modules"
Copy-Item -Path "./node_modules/*" -Destination "$directory/node_modules" -Recurse
New-Item -ItemType Directory -Path "$directory/node_modules"
Copy-Item -Path "$tempPath/node_modules/*" -Destination "$directory/node_modules" -Recurse
}
}

Expand Down
Loading

0 comments on commit 253c329

Please sign in to comment.