es-dev-commonjs-transformer
v0.2.0
Published
CommonJS Module transformer for the es-dev-server
Downloads
459
Maintainers
Readme
es-dev-commonjs-transformer
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/**/*'
])
]
}
}