diff --git a/packages/react/src/generators/library/library.spec.ts b/packages/react/src/generators/library/library.spec.ts index be647296211fb..b96594c53be3b 100644 --- a/packages/react/src/generators/library/library.spec.ts +++ b/packages/react/src/generators/library/library.spec.ts @@ -1186,5 +1186,43 @@ module.exports = withNx( " `); }); + + it('should configure files for publishable library', async () => { + await libraryGenerator(tree, { + ...defaultSchema, + bundler: 'rollup', + publishable: true, + importPath: '@acme/mylib', + unitTestRunner: 'none', + directory: 'mylib', + name: 'mylib', + }); + + expect(readJson(tree, 'mylib/package.json')).toMatchInlineSnapshot(` + { + "exports": { + ".": { + "import": "./dist/index.esm.js", + "types": "./dist/index.esm.d.ts", + }, + "./package.json": "./package.json", + }, + "files": [ + "dist", + "!**/*.tsbuildinfo", + ], + "main": "./dist/index.esm.js", + "module": "./dist/index.esm.js", + "name": "@acme/mylib", + "nx": { + "name": "mylib", + "projectType": "library", + "sourceRoot": "mylib/src", + }, + "type": "module", + "types": "./dist/index.esm.d.ts", + } + `); + }); }); }); diff --git a/packages/react/src/generators/library/library.ts b/packages/react/src/generators/library/library.ts index cfa3e4832c3a5..225a7d8b9d50a 100644 --- a/packages/react/src/generators/library/library.ts +++ b/packages/react/src/generators/library/library.ts @@ -83,6 +83,7 @@ export async function libraryGeneratorInternal(host: Tree, schema: Schema) { sourceRoot: `${options.projectRoot}/src`, tags: options.parsedTags?.length ? options.parsedTags : undefined, }, + files: options.publishable ? ['dist', '!**/*.tsbuildinfo'] : undefined, }); } else { addProjectConfiguration(host, options.name, {