DoneJS StealJS jQuery++ FuncUnit DocumentJS
4.3.0
5.0.0 3.13.1 2.3.35
  • About
  • Guides
  • API Docs
  • Community
  • Contributing
  • Bitovi
    • Bitovi.com
    • Blog
    • Design
    • Development
    • Training
    • Open Source
    • About
    • Contact Us
  • About
  • Guides
    • experiment
      • Chat Guide
      • TodoMVC Guide
      • ATM Guide
    • getting started
      • Setting Up CanJS
      • Technology Overview
      • Reading the Docs (API Guide)
      • Experimental ES Module Usage
    • recipes
      • Canvas Clock (Simple)
      • Credit Card Guide (Advanced)
      • Credit Card Guide (Simple)
      • CTA Bus Map (Medium)
      • File Navigator Guide (Advanced)
      • File Navigator Guide (Simple)
      • Playlist Editor (Advanced)
      • Signup and Login (Simple)
      • Text Editor (Medium)
      • Tinder Carousel (Medium)
      • TodoMVC with StealJS
      • Video Player (Simple)
    • topics
      • Debugging
      • Forms
    • upgrade
      • Migrating to CanJS 3
      • Migrating to CanJS 4
      • Using Codemods
  • API Docs
  • Community
  • Contributing
  • GitHub
  • Twitter
  • Chat
  • Forum
  • News
Bitovi

Experimental ES Module Usage

  • Edit on GitHub

Use ES modules' named exports feature to import just the APIs of CanJS that you are using.

CanJS provides an ES module that contains named exports which can be imported and used to pluck out the parts that you need. When used in conjunction with tree shaking you gain:

  • Fewer packages to import in each of your modules.
  • Bundles that exclude all of the parts of CanJS that you don't use.

To use, import the can/es module like so:

import { Component, DefineMap } from "can/es";

const ViewModel = DefineMap.extend({
    message: "string"
});

Component.extend({
    tag: "my-component",
    ViewModel
});

If you are using webpack tree-shaking is only available when in production mode. The following config shows a typical setup:

webpack.config.js

const path = require('path');

module.exports = {
  entry: './index.js',
  mode: 'production',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname)
  }
};

Names

The names that can be imported from this module mirror what is part of the can namespace object that you get from import can from "can". You can see the names that can/es exports here.

CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 4.3.0.

On this page

Get help

  • Chat with us
  • File an issue
  • Ask questions
  • Read latest news