enb-transpiler

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

An ENB tech that transpiles JavaScript files with ES6+ syntax to ES5 using Babel. Current stable version 0.1.2. Designed for the ENB build system, it processes files through a user-defined chain of transformations, including Babel transpilation and custom code wrapping. Differentiators: tight integration with ENB and BEM technologies, supports per-target configuration with source suffixes and chain modifiers. Released as an npm package with MIT license, maintained by b0rey. Minimal release cadence; last update in 2018.

error Error: Cannot find module 'babel-core'
cause babel-core is not installed or version mismatch.
fix
npm install --save-dev babel-core
error TypeError: techs.babel is not a function
cause Using 'techs.babel' which is undefined; Babel options must be provided as plain object.
fix
Replace with object: { presets: ['env'] }
error Error: Target '?.worker.js' not found in node's targets
cause Missing node.addTarget('?.worker.js') after tech.
fix
Add 'node.addTarget('?.worker.js')' after the addTech call.
error Error: 'source' must be last in chain
cause Incorrect chain order without ending with 'source'.
fix
Ensure chain array ends with 'source'.
breaking Version 0.1.2 removed the 'options' parameter; use 'params' instead.
fix Replace 'options' with 'params' in tech configuration.
deprecated Babel 6 is used internally; upgrade to Babel 7 by installing babel-core@^7 and providing custom params.
fix Install 'babel-core@7' and set 'params' to use Babel 7 presets/plugins.
gotcha Chain order matters: 'source' must be last to include original code; otherwise empty output.
fix Ensure the chain array ends with 'source'.
gotcha If 'sourceSuffixes' is omitted, the tech processes no files and outputs empty target.
fix Always specify 'sourceSuffixes' matching your file extensions.
gotcha The transplier tech does not support sourcemaps; errors will point to the bundle, not original files.
fix Use alternative ENB techs if sourcemaps are required.
npm install enb-transpiler
yarn add enb-transpiler
pnpm add enb-transpiler

Configures an ENB node to transpile vanilla.js and worker.js files using Babel with env preset, adding global and ym stubs.

const transpiler = require('enb-transpiler');
const FileProvideTech = require('enb/techs/file-provider');
const bemTechs = require('enb-bem-techs');

module.exports = function(config) {
  config.node('bundle', function(node) {
    node.addTechs([
      [FileProvideTech, { target: '?.bemdecl.js' }],
      [bemTechs.levels, { levels: ['blocks'] }],
      [bemTechs.deps],
      [bemTechs.files]
    ]);

    node.addTech([transpiler, {
      target: '?.worker.js',
      sourceSuffixes: ['vanilla.js', 'worker.js'],
      chain: [
        'const global = { document: { createElement: () => ({}) } }',
        'ym',
        'const modules = global.modules',
        `self.APP_VERSION = '1.0.0'`,
        'source'
      ],
      params: { presets: ['env'] }
    }]);

    node.addTarget('?.worker.js');
  });
};