Skip to content

Commit

Permalink
Remove ES module
Browse files Browse the repository at this point in the history
Removed since it causes real big application bundles if bundler isn't configured correctly
  • Loading branch information
levrik committed Nov 7, 2018
1 parent 77dde14 commit 07ec6a1
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 38 deletions.
2 changes: 0 additions & 2 deletions README-preact.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ For example the icons named `alert` and `alert-circle`:
```javascript
import AlertIcon from 'mdi-preact/AlertIcon';
import AlertCircleIcon from 'mdi-preact/AlertCircleIcon';
// If your build tools support ES module syntax and tree-shaking (like webpack 2 and above)
import { AlertIcon, AlertCircleIcon } from 'mdi-preact';

const MyComponent = () => {
return (
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ For example the icons named `alert` and `alert-circle`:
```javascript
import AlertIcon from 'mdi-react/AlertIcon';
import AlertCircleIcon from 'mdi-react/AlertCircleIcon';
// If your build tools support ES module syntax and tree-shaking (like webpack 2 and above)
import { AlertIcon, AlertCircleIcon } from 'mdi-react';

const MyComponent = () => {
return (
Expand Down
4 changes: 1 addition & 3 deletions scripts/generate-preact.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default ${component.name};
declare const ${component.name}: MdiReactIconComponentType;
export default ${component.name};
`, components => `import { FunctionalComponent } from 'preact';
`, () => `import { FunctionalComponent } from 'preact';
export interface MdiReactIconProps {
color?: string;
Expand All @@ -28,6 +28,4 @@ export interface MdiReactIconProps {
children?: never;
}
export type MdiReactIconComponentType = FunctionalComponent<MdiReactIconProps>;
${components.map(component => `declare const ${component.name}: MdiReactIconComponentType;`).join('\n')}
`).catch(err => console.error(err));
4 changes: 1 addition & 3 deletions scripts/generate-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default ${component.name};
declare const ${component.name}: MdiReactIconComponentType;
export default ${component.name};
`, components => `import { ComponentType } from 'react';
`, () => `import { ComponentType } from 'react';
export interface MdiReactIconProps {
color?: string;
Expand All @@ -27,6 +27,4 @@ export interface MdiReactIconProps {
children?: never;
}
export type MdiReactIconComponentType = ComponentType<MdiReactIconProps>;
${components.map(component => `declare const ${component.name}: MdiReactIconComponentType;`).join('\n')}
`).catch(err => console.error(err));
29 changes: 1 addition & 28 deletions scripts/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,37 +163,10 @@ async function generate(target, jsCb, tsCb, tsAllCb) {

console.log('Generating typings...');
// create the global typings.d.ts
const typingsContent = tsAllCb(components);
const typingsContent = tsAllCb();
fs.writeFileSync(path.resolve(distPath, 'typings.d.ts'), typingsContent);

console.log('Generating index...');
// create index.es.js and index.cjs.js
const indexFileContent = components
.map(component => `export { default as ${component.name} } from './${component.aliasFor || component.name}';`)
.join('\n');

const indexInputPath = path.resolve(buildPath, 'index.js');

fs.writeFileSync(indexInputPath, indexFileContent);

const bundle = await rollup.rollup({
input: indexInputPath,
...getRollupInputConfig(target)
});

await Promise.all([
bundle.write({
file: path.resolve(distPath, 'index.cjs.js'),
format: 'cjs'
}),
bundle.write({
file: path.resolve(distPath, 'index.es.js'),
format: 'es'
})
]);

// clean up
fs.unlinkSync(indexInputPath);
for (const pathToUnlink of pathsToUnlink) {
fs.unlinkSync(pathToUnlink);
}
Expand Down

2 comments on commit 07ec6a1

@felixfbecker
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the main, module and typings field removed then?

@felixfbecker
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.