San can be installed and used in many ways.
Download
from Github Releases
Both the latest and history versions are available on Github Releases.
from CDN
Skip the download and make use of the unpkg CDN:
Development:
1 | <script src="https://unpkg.com/san@latest/dist/san.dev.js"></script> |
Production:
1 | <script src="https://unpkg.com/san@latest"></script> |
Development version is recommended for development environment, it provides many useful error information and warnings!
NPM
Via NPM is recommended when used to build large-scaled applications.
NPM is a package manager with a large community, which is especially useful when it comes to development tooling.
1 | install the latest version |
CLI
San provides an official CLI for quickly scaffolding ambitious projects. It provides out-of-the-box build setup for modern front-end workflows, takes just a few minutes to get a brand new San project up and running, and comes with useful features such as hot reloading, code linting, and build versions available for production environments. It also has a graphical user interface. Details are available in the San CLI documentation.
Usage
script
It is a common way to load san via a script tag on the page. The src
URL can be either a CDN location or a local file URL.
1 | <!-- load your local copy --> |
Note: when san is being loaded,
- In AMD environment, a module named
san
will be defined. - Otherwise, a global variable named
san
will be created.
AMD
By requiring src/main.js
directly, you can build san along with your project, thus the module name can be customized.
To do this, you’ll need to make sure the packages or paths are properly configured.
1 | require.config({ |
In this example, you’ll see how to use san in AMD environment.
ESNext
In ESNext environment, san can be directly imported:
1 | import san from 'san'; |
San Component
A .san
file with the following content is called a San component
:
1 | <template> |
There’s a san-loader to load .san
files in webpack.
In this example, you’ll see how to build San component
s.
Development vs. Production
In development environment, we recommend you to use the san.dev.js
(located at san/dist/san.dev.js
).san.dev.js
provides facilities such as data validation to help you identify and solve problems more easily.
For performance considerations, the production build removes these functionalities.
There’s a production build in san releases, located at san/dist/san.js
, which is intended for production usage.
If you’re using webpack, development/production modes can be set via resolve.alias
configuration and a corresponding NODE_ENV
environment variable:
1 | { |
Finally, you can use npm scripts to apply these two webpack configurations:
1 | { |
For development:
1 | npm run dev |
Production building:
1 | npm run build |