Skip to content

JavaScript importing

History of importing

  • CommonJS
    • exports.myFunction = myFunction
    • const myFunction = require("myFile").myFunction
    • how Node.js was
  • AMD
    • async module definitions
    • Dojo
  • ES Modules

Barrel files

import { Card, SectionHeader } from "@src/Common";
import { Card } from "@src/Common/Components/Card";
import { SectionHeader } from "@src/Common/Components/SectionHeader";
  • avoid using barrel files
  • if you ever want to code split, import directly from the file

Last update: 2022-11-04