Skip to content
Open
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
50 changes: 50 additions & 0 deletions docs/Mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Production vs. Development Modes

## Pre-built Packages

As of version 14.5.0, the pre-built packages that are "compiled" will now be run
through uglify to compress them. This reduces the memory, network, and disk footprint
but makes them difficult to debug.

The "uncompiled" packages are now built with
the original uncompressed source code which is no longer wrapped in a giant `eval()`
call to make it easier to use with debugging. You can temporarily switch references
in your application to the uncompiled packages in order to perform your debugging.

## The Npm Package

As of version 14.5.0, the ilib npm package now ships with both the compressed, uglified
code as well as the original, uncompressed source code.

The uglified code now comes with sourcemap files as well. The source maps should
allow debuggers to map back to the original source code if you are debugging casually.
However, there are some browsers and modes where this does not work very well.

If you would like to debug inside of ilib more seriously, there is a way to switch
the entire ilib package to be in development/debug mode. In development mode, all of the ilib
code will be in uncompressed original files with comments and everything, and no
source maps are needed because you are using those original files.

To switch modes, there is a `switchmode` utility inside of node_modules/ilib:

```
cd node_modules/ilib
node switchmode.js development
cd ../..
```

The operation of this utility is pretty simple. It renames the "lib" directory with
the compressed files to "mini", and renames the "src" directory with the original
source files to "lib". After that, any class in your program that depends on an ilib
class will automatically load the original uncompressed source code for that ilib
class. Of course, you will have to restart your application after running this
utility in order to reload the new files.

When you are done debugging, you can switch back to production with the command:
`node switchmode.js production`

Note that if you run `npm install` after calling switch mode, it will sometimes
reset your ilib directory back to its original production configuration where `lib`
contains the compressed code, and `src` contains the original uncompressed code.
You may have to reset back to development mode after that if you still need
to do debugging.
3 changes: 3 additions & 0 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Bug Fixes:
* Updated to IANA time zone data 2019c
* Updated the Korean Name Formatting component per style. Including 'suffix' is more natural than having a 'prefix' or 'honorific'.
* Added missing likelylocale for `hr-ME`.
* Now published packages include the source maps for the uncompiled webpacked versions
so that they can be used for debugging purposes easily
* compiled versions are considered production code and are uglified as well

Build 007
-------
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Hello, and welcome to the iLib project!
* [CommonJS Modularization Support](tutorial/modules.md) as of 11.0
* [Updating the time zone information](tutorial/timezone.md)
* [Running unit test on QT/QML](QtTest.md)
* [Production and Development Modes](Mode.md)
* API Reference:
* [10.0](https://ilib-js.github.io/iLib/docs/api/10.0/jsdoc/index.html)
* [11.0](https://ilib-js.github.io/iLib/docs/api/11.0/jsdoc/index.html)
Expand Down
60 changes: 49 additions & 11 deletions js/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ limitations under the License.
<target name="prepare" depends="update.package.json" description="Prepare all directories that are needed before the project can be built">
<mkdir dir="${build.output.js}"/>
<mkdir dir="${build.output.dyncode}"/>
<mkdir dir="${build.output.dyncode}/charmaps"/>
<mkdir dir="${build.output.dyncode}/nfc"/>
<mkdir dir="${build.output.dyncode}/nfd"/>
<mkdir dir="${build.output.dyncode}/nfkc"/>
<mkdir dir="${build.output.dyncode}/nfkd"/>
<mkdir dir="${build.output.test}"/>

</target>
Expand All @@ -132,7 +137,7 @@ limitations under the License.
<sequential>
<echo>executing webpack</echo>
<exec osfamily="unix" executable="webpack-cli" dir="${build.base}" failifexecutionfails="@{failquit}" failonerror="@{failquit}">
<env key="NODE_OPTIONS" value="--max-old-space-size=3072"/>
<env key="NODE_OPTIONS" value="--max-old-space-size=4096"/>
<arg value="--env.assembly=@{assembly}"/>
<arg value="--env.size=@{size}"/>
<arg value="--env.compilation=@{compilation}"/>
Expand All @@ -143,7 +148,7 @@ limitations under the License.
<arg value="--mode=@{mode}"/>
</exec>
<exec osfamily="windows" executable="webpack-cli.bat" dir="${build.base}" failifexecutionfails="@{failquit}" failonerror="@{failquit}">
<env key="NODE_OPTIONS" value="--max-old-space-size=3072"/>
<env key="NODE_OPTIONS" value="--max-old-space-size=4096"/>
<arg value="--env.assembly=@{assembly}"/>
<arg value="--env.size=@{size}"/>
<arg value="--env.compilation=@{compilation}"/>
Expand All @@ -163,11 +168,11 @@ limitations under the License.
</uptodate>
</target>
<target name="assemble.core.assembled" depends="prepare,gen.manifest.locale,testilib.core" unless="core.ilib.core.not.needed" description="assembles the js files into a single file in the right order to satisfy dependencies">
<runassemble size="core"/>
<runassemble size="core" mode="development"/>
<runassemble size="core" compilation="compiled"/>
</target>
<target name="assemble.core.dyndata" depends="prepare,gen.manifest.locale,testilib.core" unless="core.ilib.core.not.needed" description="assembles the js files into a single file in the right order to satisfy dependencies">
<runassemble assembly="dynamicdata" size="core"/>
<runassemble assembly="dynamicdata" size="core" mode="development"/>
<runassemble assembly="dynamicdata" size="core" compilation="compiled"/>
</target>
<target name="assemble.core" depends="assemble.core.assembled,assemble.core.dyndata"/>
Expand Down Expand Up @@ -196,11 +201,11 @@ limitations under the License.
</uptodate>
</target>
<target name="assemble.standard.assembled" depends="prepare,gen.manifest.locale,testilib.standard" unless="core.ilib.standard.not.needed" description="assembles the js files into a single file in the right order to satisfy dependencies">
<runassemble size="standard"/>
<runassemble size="standard" mode="development"/>
<runassemble size="standard" compilation="compiled"/>
</target>
<target name="assemble.standard.dyndata" depends="prepare,gen.manifest.locale,testilib.standard" unless="core.ilib.standard.not.needed" description="assembles the js files into a single file in the right order to satisfy dependencies">
<runassemble assembly="dynamicdata" size="standard"/>
<runassemble assembly="dynamicdata" size="standard" mode="development"/>
<runassemble assembly="dynamicdata" size="standard" compilation="compiled"/>
</target>
<target name="assemble.standard" depends="assemble.standard.assembled,assemble.standard.dyndata"/>
Expand All @@ -213,11 +218,11 @@ limitations under the License.
</uptodate>
</target>
<target name="assemble.full.assembled" depends="prepare,gen.manifest.locale,testilib.full" unless="core.ilib.full.not.needed" description="assembles the js files into a single file in the right order to satisfy dependencies">
<runassemble size="full"/>
<runassemble size="full" mode="development"/>
<runassemble size="full" compilation="compiled"/>
</target>
<target name="assemble.full.dyndata" depends="prepare,gen.manifest.locale,testilib.full" unless="core.ilib.full.not.needed" description="assembles the js files into a single file in the right order to satisfy dependencies">
<runassemble assembly="dynamicdata" size="full"/>
<runassemble assembly="dynamicdata" size="full" mode="development"/>
<runassemble assembly="dynamicdata" size="full" compilation="compiled"/>
</target>
<target name="assemble.full" depends="assemble.full.assembled,assemble.full.dyndata"/>
Expand Down Expand Up @@ -279,11 +284,11 @@ limitations under the License.
</uptodate>
</target>
<target name="assemble.demo.assembled" depends="prepare,gen.manifest.locale,testilibdemo" unless="ilib-demo.not.needed" description="assembles the js files into a single file for the demo">
<runassemble size="demo" locales="${locales.demo}"/>
<runassemble size="demo" locales="${locales.demo}" mode="development"/>
<runassemble size="demo" compilation="compiled" locales="${locales.demo}"/>
</target>
<target name="assemble.demo.dyndata" depends="prepare,gen.manifest.locale,testilibdemo" unless="ilib-demo.not.needed" description="assembles the js files into a single file for the demo">
<runassemble assembly="dynamicdata" size="demo" locales="${locales.demo}"/>
<runassemble assembly="dynamicdata" size="demo" locales="${locales.demo}" mode="development"/>
<runassemble assembly="dynamicdata" size="demo" compilation="compiled" locales="${locales.demo}"/>
</target>
<target name="assemble.demo" depends="assemble.demo.assembled,assemble.demo.dyndata"/>
Expand Down Expand Up @@ -341,6 +346,11 @@ limitations under the License.
<arg value="-v"/>
<fileset dir="${build.lib}">
<include name="*.js"/>
<include name="charmaps/*.js"/>
<include name="nfc/*.js"/>
<include name="nfd*/.js"/>
<include name="nfkc/*.js"/>
<include name="nfkd/*.js"/>
<exclude name="ilib.js"/>
<exclude name="ilib-*.js"/>
<exclude name="externs.js"/>
Expand All @@ -355,6 +365,7 @@ limitations under the License.
</fileset>
<fileset dir="${build.base}">
<include name="index.js"/>
<include name="switchmode.js"/>
</fileset>
<mapper type="glob" from="*.js" to="*.js"/>
</apply>
Expand Down Expand Up @@ -405,16 +416,22 @@ limitations under the License.
<copy todir="${build.export}/js/assembled">
<fileset dir="${build.output.js}">
<include name="core-assembled-uncompiled-web/*.js"/>
<include name="core-assembled-uncompiled-web/*.map"/>
<include name="core-assembled-compiled-web/*.js"/>
<include name="standard-assembled-uncompiled-web/*.js"/>
<include name="standard-assembled-uncompiled-web/*.map"/>
<include name="standard-assembled-compiled-web/*.js"/>
<include name="full-assembled-uncompiled-web/*.js"/>
<include name="full-assembled-uncompiled-web/*.map"/>
<include name="full-assembled-compiled-web/*.js"/>
<include name="core-dynamicdata-uncompiled-web/*.js"/>
<include name="core-dynamicdata-uncompiled-web/*.map"/>
<include name="core-dynamicdata-compiled-web/*.js"/>
<include name="standard-dynamicdata-uncompiled-web/*.js"/>
<include name="standard-dynamicdata-uncompiled-web/*.map"/>
<include name="standard-dynamicdata-compiled-web/*.js"/>
<include name="full-dynamicdata-uncompiled-web/*.js"/>
<include name="full-dynamicdata-uncompiled-web/*.map"/>
<include name="full-dynamicdata-compiled-web/*.js"/>
</fileset>
</copy>
Expand Down Expand Up @@ -457,6 +474,7 @@ limitations under the License.
<copy todir="${build.export}/package/lib">
<fileset dir="${build.export}/js/dyncode">
<include name="**/*"/>
<exclude name="externs.js"/>
<exclude name="*Loader.js"/>
<exclude name="ilib-web.js"/>
<exclude name="ilib-qt.js"/>
Expand All @@ -478,9 +496,29 @@ limitations under the License.
<copy todir="${build.export}/package">
<fileset dir="${build.export}/js/dyncode">
<include name="index.js"/>
<include name="switchmode.js"/>
</fileset>
</copy>
<copy todir="${build.export}/package/locale">
<mkdir dir="${build.export}/package/src" description="Dir to contain all the exported source files"/>
<copy todir="${build.export}/package/src">
<fileset dir="${build.base}/lib">
<include name="**/*.js"/>
<exclude name="externs.js"/>
<exclude name="metafiles/*"/>
<exclude name="ilib-qt.js"/>
<exclude name="ilib-rhino.js"/>
<exclude name="ilib-ringo.js"/>
<exclude name="ilib-web.js"/>
<exclude name="*Loader.js"/>
</fileset>
<fileset dir="${build.base}/lib">
<include name="Loader.js"/>
<include name="RhinoLoader.js"/>
<include name="WebpackLoader.js"/>
<include name="NodeLoader.js"/>
</fileset>
</copy>
<copy todir="${build.export}/package/locale">
<fileset dir="${build.locale}">
<include name="**/*.json"/>
</fileset>
Expand Down
2 changes: 1 addition & 1 deletion js/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* index.js - top level entry point for ilib
*
* Copyright © 2018 JEDLSoft
* Copyright © 2018-2020 JEDLSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 2 additions & 0 deletions js/package.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
"files": [
"lib",
"locale",
"src",
"index.js",
"switchmode.js",
"README.md",
"LICENSE"
],
Expand Down
42 changes: 42 additions & 0 deletions js/switchmode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* switchmode.js - switch the ilib npm package to production or development mode
*
* Copyright © 2020 JEDLSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var fs = require("fs");

var args = process.argv;

if (args[2] === "-h" || args[2] === "--help") {
console.log("Usage: switchmode.sh '(production|development)'");
console.log("Switch ilib to the compressed/production mode or the uncompressed/development mode.");
process.exit(0);
}

if (args[2] === "production") {
if (!fs.existsSync("./src")) {
fs.renameSync("lib", "src");
fs.renameSync("mini", "lib");
}
console.log("ilib is now in production mode.");
} else {
if (!fs.existsSync("./mini")) {
fs.renameSync("lib", "mini");
fs.renameSync("src", "lib");
}
console.log("ilib is now in development mode.");
}
6 changes: 6 additions & 0 deletions js/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = function(env, args) {
locales = env.locales,
ilibRoot = path.resolve(env.ilibRoot || "."),
tempDirRoot = path.resolve(env.tempDir || "temp"),
mode = args.mode,
outputPath;

// "ut" is unit tests
Expand Down Expand Up @@ -108,6 +109,11 @@ module.exports = function(env, args) {
]
};

if (mode === "development") {
console.log("Using development mode");
ret.devtool = "hidden-source-map";
}

if (target !== "web") {
ret.target = target;
}
Expand Down