Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: ljharb <ljharb@gmail.com> BREAKING CHANGE: This package now includes [conditional package exports][docs]. Most consumers should be able to upgrade without any issues, however, package exports limits the allowed entry points inside of Node.js and also affects consumption in other bundlers. - `main` targets been updated to support down to node 4 (ES5) - `module` targets has update to support down to node 6 (ES2015) - `exports` targets have been set to node 12 (ES2019) - `unpkg` targets have been set to browserslist `defaults` [docs]: https://nodejs.org/api/packages.html#conditional-exports
- Loading branch information
1 parent
5cb8d66
commit 31b79a1
Showing
8 changed files
with
144 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/dist | ||
/build | ||
/coverage | ||
node_modules | ||
dist | ||
build | ||
coverage | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import babel from '@rollup/plugin-babel'; | ||
import resolve from '@rollup/plugin-node-resolve'; | ||
|
||
const input = './src/index.ts'; | ||
|
||
// please update the package.json to reflect any changes here | ||
const bundles = createBundles({ | ||
// the `unpkg` UMD bundle (for usage without a bundler) | ||
unpkg: { | ||
format: 'umd', | ||
targets: 'defaults', | ||
output: { name: 'color2k' }, | ||
}, | ||
// legacy node bundle (note: this is currently used in jest-resolve) | ||
main: { | ||
format: 'cjs', | ||
targets: 'node 4', | ||
}, | ||
// the `module` bundle that should support older bundlers that used this entry | ||
// point. (e.g. webpack 2) | ||
module: { | ||
format: 'es', | ||
// `node 6` is a good target because it's closest to es2015 specified in the | ||
// rollup spec: https://github.com/rollup/rollup/wiki/pkg.module | ||
targets: 'node 6', | ||
}, | ||
exports: { | ||
// `node 12` is a good target because: | ||
// | ||
// this module entry point is used by several bundlers. | ||
// namely: webpack, @rollup/plugin-node-resolve, wmr (via rollup) | ||
// | ||
// the lowest common denominator is **acorn 7** with ecmaVersion `2019` | ||
// - @rollup/plugin-node-resolve supports as low as rollup 1.2 | ||
// - rollup 1.2 uses acorn 7 with ecmaVersion `2019` https://github.com/rollup/rollup/blob/v1.2.0/src/Module.ts#L105 | ||
// - webpack uses acorn 8 with ecmaVersion latest https://github.com/webpack/webpack/blob/v5.0.0/lib/javascript/JavascriptParser.js#L128 | ||
// - node 12 is the first version to completely support ES2019 https://node.green/#ES2019 | ||
// | ||
// this module entry point is used by esbuild too. | ||
// https://esbuild.github.io/api/#how-conditions-work | ||
import: { | ||
format: 'es', | ||
targets: 'node 12', | ||
extension: 'mjs', | ||
}, | ||
require: { | ||
format: 'cjs', | ||
targets: 'node 12', | ||
}, | ||
}, | ||
}); | ||
|
||
function createBundles(config, parents = []) { | ||
if ('targets' in config) { | ||
const { format, extension = 'js', output, targets } = config; | ||
|
||
return [ | ||
{ | ||
input, | ||
output: { | ||
file: `./dist/index.${parents.join('.')}.${format}.${extension}`, | ||
format, | ||
sourcemap: true, | ||
...output, | ||
}, | ||
plugins: [ | ||
resolve({ extensions: ['.ts'], modulesOnly: true }), | ||
babel({ | ||
babelrc: false, | ||
configFile: false, | ||
babelHelpers: 'bundled', | ||
extensions: ['.ts'], | ||
targets, | ||
presets: [ | ||
['@babel/preset-env', { targets }], | ||
'@babel/preset-typescript', | ||
], | ||
}), | ||
], | ||
}, | ||
]; | ||
} | ||
|
||
return Object.entries(config).flatMap(([key, subConfig]) => | ||
createBundles(subConfig, [...parents, key]) | ||
); | ||
} | ||
|
||
export default bundles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
# use node_modules/.bin first | ||
PATH=./node_modules/.bin:$PATH | ||
|
||
# exit on any error | ||
set -e | ||
|
||
# clean | ||
rm -rf dist | ||
|
||
# build js | ||
rollup -c | ||
|
||
# generate types | ||
tsc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters