2
0
mirror of https://github.com/iconify/iconify.git synced 2024-12-14 14:38:25 +00:00
iconify/packages/library-builder
2021-12-11 23:10:26 +01:00
..
src chore: update library-builder to work on windows os 2021-12-11 23:10:26 +01:00
tests Create script for building ES and CommonJS libraries, move Utils and Core to new build process, move Redundancy package to monorepo and refactor it 2021-09-20 12:59:16 +03:00
.editorconfig Create script for building ES and CommonJS libraries, move Utils and Core to new build process, move Redundancy package to monorepo and refactor it 2021-09-20 12:59:16 +03:00
.eslintignore Create script for building ES and CommonJS libraries, move Utils and Core to new build process, move Redundancy package to monorepo and refactor it 2021-09-20 12:59:16 +03:00
.eslintrc.js Fix generated exports by library-builder package 2021-09-23 23:35:38 +03:00
.gitignore Create script for building ES and CommonJS libraries, move Utils and Core to new build process, move Redundancy package to monorepo and refactor it 2021-09-20 12:59:16 +03:00
.npmignore Create script for building ES and CommonJS libraries, move Utils and Core to new build process, move Redundancy package to monorepo and refactor it 2021-09-20 12:59:16 +03:00
.prettierrc Create script for building ES and CommonJS libraries, move Utils and Core to new build process, move Redundancy package to monorepo and refactor it 2021-09-20 12:59:16 +03:00
jest.config.js Create script for building ES and CommonJS libraries, move Utils and Core to new build process, move Redundancy package to monorepo and refactor it 2021-09-20 12:59:16 +03:00
license.txt Create script for building ES and CommonJS libraries, move Utils and Core to new build process, move Redundancy package to monorepo and refactor it 2021-09-20 12:59:16 +03:00
package-lock.json Publish stable versions of all packages, update dependencies 2021-11-11 10:22:19 +02:00
package.json Fix main entry in library builder 2021-11-06 22:53:42 +02:00
readme.md Create script for building ES and CommonJS libraries, move Utils and Core to new build process, move Redundancy package to monorepo and refactor it 2021-09-20 12:59:16 +03:00
tsconfig-base.json Create script for building ES and CommonJS libraries, move Utils and Core to new build process, move Redundancy package to monorepo and refactor it 2021-09-20 12:59:16 +03:00
tsconfig.json Create script for building ES and CommonJS libraries, move Utils and Core to new build process, move Redundancy package to monorepo and refactor it 2021-09-20 12:59:16 +03:00

ES Builder

This is a library for transpiling TypeScript files.

It is not a bundler! It builds libraries that export multiple single files, not bundles.

What does it do?

  • Creates both ES and CommonJS modules in target directory. CommonJS files use '.js' extension, ES files use '.mjs' extension.
  • Creates TypeScript definition files for each file.
  • Rewrites imports paths in ES modules.
  • Updates exports field in package.json
  • Tests ES imports

Why is it needed?

  • ES modules should have full import paths, including extension, but TypeScript compiler cannot rewrite imports, so it cannot change target extension, so tsc cannot be reliably used to create ES modules.
  • Using other tools, such as esbuild requires custom plugin. This package is used by multiple packages, so it makes sense to split code into a separate package to make it easily reusable.
  • Currently tsup is the only viable alternative, but it is meant to be used as bundler. Without bundle option it currently fails to generate TypeScript definition files.
  • Reusable functions for updating package.json and for testing ES imports.

Documentation

Requirements for using build process:

  • Create tsconfig.json that creates CommonJS modules, saves declarations, has importsNotUsedAsValues set to error.
  • Add script to package.json for building source code, such as "build:source": "tsc -b",. If you have multipe

To build packages, create build.js in your package:

/* eslint-disable */
const { buildFiles } = require('@iconify/library-builder');

buildFiles({
	root: __dirname,
	source: './src',
	target: './lib',
})
	.then(() => {
		console.log('Done');
	})
	.catch((err) => {
		console.error(err);
		process.exit(1);
	});

Source and target paths must be relative to root directory and start with ./.

License

The library is released with MIT license.

© 2021 Vjacheslav Trushkin / Iconify OÜ