es-dev-commonjs-transformer

0.2.0 • Public • Published

es-dev-commonjs-transformer

npm version

CommonJS Module transformer for the es-dev-server. It converts modules cjs -> esm format. Uses Rollup commonjs plugin under the hood.

// In
const a = require('dep');
...
module.exports = a;
// Out
import a from 'dep';
...
export default a;

General Usage

//es-dev-server.config.js
 
import cjsTransformer from 'es-dev-commonjs-transformer';
 
module.exports = {
    responseTransformers: [
        cjsTransformer(/* Exclude Paths Array */ [
            '**/node_modules/@open-wc/**/*',
            ...
        ])
    ]
}

OpenWC Karma Testing Setup

The Open-wc karma setup requires you to exlude some paths from being processed by the cjs transformer. The following excludes seems to have worked for me.

//karma.conf.ts
 
const cjsTransformer = require('es-dev-commonjs-transformer');
const { createDefaultConfig } = require('@open-wc/testing-karma');
 
module.exports = config => {
    let defaultConfig = createDefaultConfig(config);
    
    ...
    
    esm: {
        responseTransformers: [
        cjsTransformer([
                ...defaultConfig.esm.babelModernExclude,
                '**/node_modules/@open-wc/**/*',
                '**/node_modules/chai-dom/**/*',
                '**/node_modules/sinon-chai/**/*'
            ])
        ]
    }
}

Package Sidebar

Install

npm i es-dev-commonjs-transformer

Weekly Downloads

124

Version

0.2.0

License

MIT

Unpacked Size

5.74 kB

Total Files

4

Last publish

Collaborators

  • ashubham