es6-module-transpiler-coffee-brunch

raw JSON →
0.1.0 verified Fri May 01 auth: no javascript maintenance

Brunch plugin that compiles CoffeeScript files through coffee-script and then Square's es6-module-transpiler to produce AMD or CommonJS modules with ES6 module syntax (import/export). Version 0.1.0 is the latest and only release. This plugin is a stop-gap alternative to ember-cli for ES6 module transpiling in CoffeeScript codebases using Brunch. It is effectively limited to AMD output due to CommonJS interoperability issues. Requires manual backtick escaping of ES6 syntax in CoffeeScript.

error Error: Cannot find module 'es6-module-transpiler'
cause Missing required dependency es6-module-transpiler.
fix
Run: npm install es6-module-transpiler
error Error: ENOTDIR: not a directory, scandir '/path/to/app'
cause Brunch expects source files under 'app' directory; plugin may not find files if directory structure is different.
fix
Ensure CoffeeScript files are under a directory named 'app' or configure brunch's paths accordingly.
gotcha ES6 module syntax must be escaped with backticks in CoffeeScript files.
fix Use backticks around import/export statements as shown in README.
gotcha CommonJS output may not work correctly; recommended to use AMD wrapper.
fix Set wrapper to 'amd' in configuration.
gotcha Do not use coffee-script-brunch simultaneously; this plugin replaces it.
fix Remove coffee-script-brunch from package.json and run npm prune.
gotcha Brunch's module wrapper must be disabled when using AMD wrapper.
fix Set modules.wrapper: false in brunch config.
gotcha Configuration key must be plugins.es6ModuleTranspiler (not es6_module_transpiler).
fix Use camelCase key: es6ModuleTranspiler in the plugins section.
npm install es6-module-transpiler-coffee-brunch
yarn add es6-module-transpiler-coffee-brunch
pnpm add es6-module-transpiler-coffee-brunch

Shows configuration with brunch module wrapper disabled, transpiler set to AMD, and a CoffeeScript file using backtick-escaped ES6 import/export.

// In config.coffee
exports.config =
  modules:
    wrapper: false # Disable brunch's module wrapper
  plugins:
    es6ModuleTranspiler:
      wrapper: 'amd'  # or 'cjs'
      moduleName: (path) -> 'myapp/' + path
      options:
        imports:
          underscore: '_'
        global: 'MyApp'

// In app/snake.coffee
`import Animal from 'animal';`

class Snake extends Animal
  move: ->
    alert "Slithering..."
    super 5

`export default Snake;`