mirror of
https://github.com/danog/react-datalist-input.git
synced 2024-12-13 09:57:22 +01:00
0423540ae7
- moves project to babel 7 - moves from webpack to rollup - adds react and react-dom to dev dependencies - adds react-testing-libary and jest - adds first unit test - adds eslint and eslint plugins to dev dependencies
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const path = require('path');
|
|
const camelcase = require('camelcase');
|
|
|
|
// This is a custom Jest transformer turning file imports into filenames.
|
|
// http://facebook.github.io/jest/docs/en/webpack.html
|
|
|
|
module.exports = {
|
|
process(src, filename) {
|
|
const assetFilename = JSON.stringify(path.basename(filename));
|
|
|
|
if (filename.match(/\.svg$/)) {
|
|
// Based on how SVGR generates a component name:
|
|
// https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6
|
|
const pascalCaseFileName = camelcase(path.parse(filename).name, {
|
|
pascalCase: true,
|
|
});
|
|
const componentName = `Svg${pascalCaseFileName}`;
|
|
return `const React = require('react');
|
|
module.exports = {
|
|
__esModule: true,
|
|
default: ${assetFilename},
|
|
ReactComponent: React.forwardRef(function ${componentName}(props, ref) {
|
|
return {
|
|
$$typeof: Symbol.for('react.element'),
|
|
type: 'svg',
|
|
ref: ref,
|
|
key: null,
|
|
props: Object.assign({}, props, {
|
|
children: ${assetFilename}
|
|
})
|
|
};
|
|
}),
|
|
};`;
|
|
}
|
|
|
|
return `module.exports = ${assetFilename};`;
|
|
},
|
|
};
|