Nodejs
# npm
npm install --save suchjs
# yarn
yarn add suchjs
# pnpm
pnpm add suchjs
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
// CMD
const { default: globalSuch, createNsSuch } = require("suchjs");
// ES6 module
import globalSuch, { createNsSuch } from "suchjs";
1
2
3
4
2
3
4
In the nodejs environment, suchjs has the ability to load configuration files, the format of the configuration file can be viewed in API Such.config
Browser
use npm
the installation is same as in the 'nodejs'
demo:
// here imported from the path 'suchjs/lib/browser', not 'suchjs' import globalSuch, { createNsSuch } from "suchjs/lib/browser";
1
2use the CDN or local file
Copy the
dist/such.min.js
file (or some other version) in the project to the local or upload to the CDN, use the script tag include to the html page, it will export a globalSuch
object mounted by thewindow
. Thewindow.Such
object look like below:// the default is a global Such instance, and use `createNsSuch` you will get a namespace instance const { default: globalSuch, createNsSuch } = window.Such;
1
2if you use the tool
webpack
, then you can configure the 'externals':// webpack module.exports = { // externals externals: { suchjs: "Such", }, };
1
2
3
4
5
6
7then used in the javascript code like this:
import globalSuch, { createNsSuch } from "suchjs";
1