On this page:
The mapping for this definitions is equivalent to the following code:
The generated code exports the top-level modules. For browsers it adds symbols to the global window object and for NodeJS it uses the native exports object.
When developing for NodeJS, you include the various Ice components with
require statements as shown below:
Importing the generated code for your own Slice definitions works the same way:
This example assumes the generated Slice definitions are in the file
Ice.js shown above only provides definitions for the Ice run time; you would need to explicitly include the corresponding files for any other Ice components that your application needs, such as
[["js:es6-module"]] file metadata to enable the new module mapping:
--module es6 to tell the compiler that you want to resolve imports using es6 modules.
Using "ice" module in the browser
The "ice" NPM package can be used for web browser applications, in conjunction with a module bundler that has support for CommonJS modules like WebPack, Rollup, or Vite. You have to configure the bundler to exclude the "fs" and "net" modules that are only required for NodeJS applications. See bellow for detailed configuration examples:
The file metadata [["
The Gulp Ice Builder will generate a bundle for the "chat" module named
chat.js, when the typescript option is enabled it will also generate a TypeScript definitions file
chat.d.ts, you can use the generated code by importing the generated chat.js file from your application as in:
The generated code for Slice definitions in a different module, will import the "chat" module as show in the following sample
- Using the Slice Compilers