Sign in Join
Wiki copytemporary

pas2js minifier: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11# Overview
22
33This page explains ways to reduce and/or compress the pas2js generated JavaScript.
44
55For a complete list of optimizations, including ideas not yet implemented, see [[Pas2js optimizations]]
66
77# Omit unneeded code
88
99- Use pas2js option -Jc to generate one JavaScript program. This allows the compiler to use Whole Program Optimization (wpo) to determine all unused identifiers.
1010- Use -O1 to omit unused identifiers. If a record/class is used, every unused member/method is omitted.
1111- By default published properties/methods are kept and will generate type information (RTTI). If you don't need that you can ...
1212 - use {\$modeswitch omitrtti} (since pas2js 1.1), which treats class section 'published' as 'public' and *typeinfo()* does not work on symbols declared with this switch.
1313 - use -OoRemoveNotUsedPublished to omit all published properties not referenced at compile time.
1414
1515# Third party minifier
1616
1717There are several free minifiers for JavaScript. A minifier removes unneeded characters and replaces some code without changing its functionality.
1818
1919**Sourcemaps**: Keep in mind that third party minifiers usually makes the source map of pas2js unusable, so use the third party minifier only for the release version.
2020
2121As an example here is how to use uglifyjs with pas2js:
2222
2323## Windows
2424
2525- Download and install "node" form <https://nodejs.org/en/download/>
2626- Start the "Node.js command prompt". This starts a console, which is setup with an environment for *Node.js* and *npm*.
2727- In the prompt type
2828
29-`npm install uglify-js -g`
29+```text
30+npm install uglify-js -g
31+```
3032
3133and press \<enter\> This will download and install uglifyjs as a command line app. Test it by typing
3234
33-`uglifyjs -h`
35+```text
36+uglifyjs -h
37+```
3438
3539This should give the list of uglifyjs options.
3640
3741- After install restart applications like Lazarus so they get the new PATH, which is needed by uglifyjs to work.
3842- Find out the path of uglifyjs.cmd, for example by typing *where uglifyjs*
3943- In Lazarus:
4044 - With pas2js 1.1: Add to the custom compiler options **"-JpcmdC:\path\of\uglifyjs.cmd"**. Note that *-Jpcmd* is case sensitive.
4145 - With pas2js 1.0: Set the *Execute After* command: *C:\path\of\uglifyjs.cmd -oproject1.js project1.js*. Replace *project1.js* with the name of your js file.
4246
4347## Linux/MacOS
4448
4549- Install npm
4650- Open a terminal and do:
4751
48-`sudo npm install uglify-js -g`
52+```text
53+sudo npm install uglify-js -g
54+```
4955
5056This will download and install uglifyjs as a command line app. Test it by typing
5157
52-`uglifyjs -h`
58+```text
59+uglifyjs -h
60+```
5361
5462This should give the list of uglifyjs options.
5563
5664- In Lazarus:
5765 - With pas2js 1.1: Add to the custom compiler options **-Jpcmduglifyjs**. This is the option *-Jpcmd* plus the path to *uglifyjs*.
5866 - With pas2js 1.0: Set the *Execute After* command: *uglifyjs -oproject1.js project1.js*. Replace *project1.js* with the name of your js file.
5967
6068---
6169*From the Free Pascal wiki, page "pas2js minifier", as it stood on 2021-03-28 after a change by Mattias2, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
6270Category: Pas2js

Back to history