# Building GoJS from TypeScript Sources

All customers can use the `go.js` and `go-debug.js` files to run their app. However, if you have purchased a license to the GoJS TypeScript source code, you can build your app from the TypeScript source. Popular module bundlers such as Webpack are able to remove a number of modules from the source, provided you are not using them, to shrink the size of the deliverable file.

Because the `go.js` and `go-debug.js` files are built in a custom process to reduce size, using Webpack or another bundler with the GoJS source, even though it removes unused modules, may result in a larger file size than just using `go.js`. However, TypeScript authors may appreciate the feedback and debugging capabilities of building from source.

## MinimalSource and MaximalSource projects

The GoJS kit has two subdirectories under the `/projects` directory, `/minimalSource` and `/maximalSource`.

The minimalSource project shows how to build GoJS while removing all possible optional modules. The maximalSource project shows how to build GoJS while matching the functionality of the released go.js and go-debug.js files.

Both projects require `webpack` and `npm` to run.

There is additionally minimalSourceBrowserify, which shows how to build from source with Browserify instead of Webpack.

## Classes/modules that can be removed when building from source

Several classes, such as `CommandHandler` and the Tools, may be essential to add to your project, while others such as all but one `Layout` and one type of `Model` can often be removed. Below is a list of modules that webpack can remove from builds, provided they are not referenced in your code:

- CommandHandler, required for keyboard functionality.
- `SVGSurface`, required to call Diagram.makeSVG
- TreeModel
- GraphLinksModel, without loading this module, the default Diagram.model is of type `Model`.
- Overview
- Palette

Layouts:

- GridLayout
- TreeLayout
- LayeredDigraphLayout
- CircularLayout
- ForceDirectedLayout,

Mouse-down tools:

- ActionTool
- RelinkingTool
- LinkReshapingTool
- ResizingTool
- RotatingTool

Mouse-move tools:

- LinkingTool
- DraggingTool
- DragSelectingTool
- PanningTool

Mouse-up tools:

- ContextMenuTool
- TextEditingTool
- ClickCreatingTool
- ClickSelectingTool

There are several "built in" Panel types, each of which is a PanelLayout. Some of these are required for building the source:

- `PanelLayoutPosition`
- `PanelLayoutVertical`
- `PanelLayoutLink`
- `PanelLayoutAuto`
- `PanelLayoutGrid`

However, it is possible to build without the following panel types:

- `PanelLayoutHorizontal`
- `PanelLayoutSpot`
- `PanelLayoutTable`
- `PanelLayoutViewbox`
- `PanelLayoutTableRow`
- `PanelLayoutTableColumn`
- `PanelLayoutGraduated`

The source index files demonstrate the necessary calls to `Panel.addPanelLayout` to include each panel type.

## Using the optional classes

Many of the classes simply need to be used to be included in source building. For some functionality, like the Tools, CommandHandler, and SVGSurface, you need to make sure you explicitly initalize them. Examples of this can be found in the maximal-index.ts code for the maximalSource project. Doing so is not necessary with the full `go.js` library because the `go` object already has references to each.

A typical GoJS project is not expected to remove all or even most of these modules, and may use the majority of them. Because Northwood's internal build process is optimized to use the Google Closure Compiler in Advanced Mode, it may take considerable effort to produce a `go.js` bundle from source that is smaller than the one we include in the project's release directory.

## Important license information about GoJS source code

The GoJS source code is subject to the terms of our license, contained in SoftwareLicenseAgreement.pdf.

Do not use, release (deploy), or distribute the unminified source code. To build GoJS for your own application you must use a popular obfuscation/minification tool, such as the Google Closure Compiler.