Skip to content

Commit

Permalink
feat(react): update subfolder exports for icons (#11318)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblack authored May 2, 2022
1 parent fd67028 commit 4f855c4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
2 changes: 2 additions & 0 deletions packages/react/icons/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/index.esm.js
/index.js
4 changes: 2 additions & 2 deletions packages/react/icons/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"main": "lib/index.js",
"module": "es/index.js",
"main": "index.js",
"module": "index.esm.js",
"sideEffects": false
}
File renamed without changes.
56 changes: 32 additions & 24 deletions packages/react/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ const stripBanner = require('rollup-plugin-strip-banner');
const packageJson = require('../package.json');

async function build() {
const entrypoints = [
{
filepath: path.resolve(__dirname, '..', 'src', 'index.js'),
outputDirectory: path.resolve(__dirname, '..'),
},
{
filepath: path.resolve(__dirname, '..', 'icons', 'index.js'),
outputDirectory: path.resolve(__dirname, '..', 'icons'),
},
];
const reactEntrypoint = {
filepath: path.resolve(__dirname, '..', 'src', 'index.js'),
outputDirectory: path.resolve(__dirname, '..'),
};
const iconsEntrypoint = {
filepath: path.resolve(__dirname, '..', 'icons', 'src', 'index.js'),
outputDirectory: path.resolve(__dirname, '..', 'icons'),
};
const formats = [
{
type: 'esm',
Expand All @@ -37,25 +35,35 @@ async function build() {
},
];

for (const entrypoint of entrypoints) {
const inputConfig = getRollupConfig(entrypoint.filepath);
const bundle = await rollup(inputConfig);
const reactInputConfig = getRollupConfig(reactEntrypoint.filepath);
const reactBundle = await rollup(reactInputConfig);

for (const format of formats) {
await reactBundle.write({
dir: path.join(reactEntrypoint.outputDirectory, format.directory),
format: format.type,
preserveModules: true,
preserveModulesRoot: path.dirname(reactEntrypoint.filepath),
banner,
exports: 'named',
});
}

for (const format of formats) {
await bundle.write({
dir: path.join(entrypoint.outputDirectory, format.directory),
format: format.type,
preserveModules: true,
preserveModulesRoot: path.dirname(entrypoint.filepath),
banner,
exports: 'named',
});
}
const iconsInputConfig = getRollupConfig(iconsEntrypoint.filepath);
const iconsBundle = await rollup(iconsInputConfig);
for (const format of formats) {
await iconsBundle.write({
file:
format.type === 'commonjs' ? 'icons/index.js' : 'icons/index.esm.js',
format: format.type,
banner,
exports: 'named',
});
}
}

const banner = `/**
* Copyright IBM Corp. 2016, 2021
* Copyright IBM Corp. 2016, 2022
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down

0 comments on commit 4f855c4

Please sign in to comment.