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
- Host: GitHub
- URL: https://github.com/ashubham/es-dev-commonjs-transformer
- Owner: ashubham
- License: mit
- Created: 2019-12-05T17:31:48.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-15T18:48:09.000Z (almost 5 years ago)
- Last Synced: 2025-03-13T11:39:38.292Z (about 1 month ago)
- Language: JavaScript
- Size: 20.5 KB
- Stars: 5
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# es-dev-commonjs-transformer
[](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.jsimport 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.tsconst 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/**/*'
])
]
}
}
```