mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
* cake doc:site:watch should also watch the changelog files * Changelog for 2.4.0 * 2.4.0 output
22 lines
1.1 KiB
Markdown
22 lines
1.1 KiB
Markdown
## Modules
|
|
|
|
ES2015 modules are supported in CoffeeScript, with very similar `import` and `export` syntax:
|
|
|
|
```
|
|
codeFor('modules')
|
|
```
|
|
|
|
<div id="dynamic-import" class="bookmark"></div>
|
|
|
|
[Dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports) is also supported, with mandatory parentheses:
|
|
|
|
```
|
|
codeFor('dynamic_import', true)
|
|
```
|
|
|
|
<div id="modules-note" class="bookmark"></div>
|
|
|
|
Note that the CoffeeScript compiler **does not resolve modules**; writing an `import` or `export` statement in CoffeeScript will produce an `import` or `export` statement in the resulting output. It is your responsibility to [transpile](#transpilation) this ES2015 syntax into code that will work in your target runtimes.
|
|
|
|
Also note that any file with an `import` or `export` statement will be output without a [top-level function safety wrapper](#lexical-scope); in other words, importing or exporting modules will automatically trigger [bare](#usage) mode for that file. This is because per the ES2015 spec, `import` or `export` statements must occur at the topmost scope.
|