Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Common CI Configuration
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
Common CI Configuration
Merge requests
!72
Support for common definition of pnpm config like also sharing helper scripts used while building NPM applications
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Support for common definition of pnpm config like also sharing helper scripts used while building NPM applications
bw_common_config
into
develop
Overview
0
Commits
6
Pipelines
10
Changes
1
Merged
Bartek Wrona
requested to merge
bw_common_config
into
develop
1 month ago
Overview
0
Commits
6
Pipelines
10
Changes
1
Expand
0
0
Merge request reports
Viewing commit
19a39f4d
Prev
Next
Show latest version
1 file
+
66
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
19a39f4d
Add terser script to ts common scripts
· 19a39f4d
Mateusz Tyszczak
authored
1 month ago
ts-common/terser.ts
0 → 100644
+
66
−
0
Options
import
type
{
MinifyOptions
}
from
"
terser
"
;
import
{
minify
}
from
"
terser
"
;
import
{
readdirSync
,
readFileSync
,
statSync
,
writeFileSync
}
from
"
node:fs
"
;
import
{
resolve
,
join
,
dirname
}
from
"
node:path
"
;
import
{
fileURLToPath
}
from
'
node:url
'
;
import
{
existsSync
}
from
"
node:fs
"
;
const
__dirname
=
dirname
(
fileURLToPath
(
import
.
meta
.
url
));
const
packageJsonLocation
=
join
(
process
.
cwd
(),
"
package.json
"
);
const
{
files
}
=
JSON
.
parse
(
readFileSync
(
packageJsonLocation
,
{
encoding
:
"
utf-8
"
}));
// =============== #1 ANALYZE "files" in package.json and collect all .js sources ===============
const
jsSources
:
string
[]
=
[];
const
analyzePath
=
(
path
:
string
)
=>
{
if
(
!
existsSync
(
path
))
{
console
.
warn
(
`The path
${
path
}
does not exist`
);
return
;
}
if
(
statSync
(
path
).
isFile
())
{
if
(
path
.
endsWith
(
"
.js
"
))
jsSources
.
push
(
resolve
(
__dirname
,
path
));
return
;
}
for
(
const
file
of
readdirSync
(
path
,
{
withFileTypes
:
true
}))
analyzePath
(
join
(
file
.
parentPath
,
file
.
name
));
}
for
(
const
file
of
files
)
analyzePath
(
resolve
(
file
));
// =============== #2 Define terser minification configuration ===============
const
minifyOptions
:
MinifyOptions
=
{
compress
:
true
,
mangle
:
false
,
ecma
:
2020
,
ie8
:
false
,
keep_classnames
:
true
,
keep_fnames
:
true
,
sourceMap
:
false
,
format
:
{
inline_script
:
false
,
comments
:
false
,
max_line_len
:
100
}
};
// =============== #3 Minify the files ===============
for
(
const
file
of
jsSources
)
{
const
inputCode
=
readFileSync
(
file
,
{
encoding
:
"
utf-8
"
});
void
minify
(
inputCode
,
minifyOptions
).
then
(({
code
})
=>
{
if
(
!
code
)
throw
new
Error
(
`Failed to minify the file
${
file
}
`
);
writeFileSync
(
file
,
code
,
{
encoding
:
"
utf-8
"
});
console
.
log
(
`Minified
${
file
}
`
);
});
}
Loading