An open API service indexing awesome lists of open source software.

https://github.com/ashubham/es-dev-commonjs-transformer

CommonJS Module transformer for the es-dev-server
https://github.com/ashubham/es-dev-commonjs-transformer

Last synced: 22 days ago
JSON representation

CommonJS Module transformer for the es-dev-server

Awesome Lists containing this project

README

        

# es-dev-commonjs-transformer
[![npm version](https://badge.fury.io/js/es-dev-commonjs-transformer.svg)](https://badge.fury.io/js/es-dev-commonjs-transformer)

CommonJS Module transformer for the es-dev-server. It converts modules cjs -> esm format. Uses [Rollup commonjs plugin](https://github.com/rollup/rollup-plugin-commonjs) under the hood.

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

## General Usage

```js
//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.

```js
//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/**/*'
])
]
}
}
```