Skip to content

Commit

Permalink
fix(react): default bundler to vite when deprecated buildable option …
Browse files Browse the repository at this point in the history
…is used (#13857)
  • Loading branch information
jaysoo committed Dec 15, 2022
1 parent 0eadfc8 commit 99983e9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
Expand Up @@ -85,4 +85,37 @@ describe('normalizeOptions', () => {
unitTestRunner: 'jest',
});
});

it('should set bundler to rollup if buildable is true not no bundler is passed', () => {
const options = normalizeOptions(tree, {
name: 'test',
style: 'css',
linter: Linter.None,
buildable: true,
unitTestRunner: 'jest',
});

expect(options).toMatchObject({
buildable: true,
bundler: 'rollup',
unitTestRunner: 'jest',
});
});

it('should set bundler to rollup if buildable is true and bundler is none ', () => {
const options = normalizeOptions(tree, {
name: 'test',
style: 'css',
linter: Linter.None,
buildable: true,
bundler: 'none',
unitTestRunner: 'jest',
});

expect(options).toMatchObject({
buildable: true,
bundler: 'rollup',
unitTestRunner: 'jest',
});
});
});
22 changes: 19 additions & 3 deletions packages/react/src/generators/library/lib/normalize-options.ts
Expand Up @@ -4,6 +4,7 @@ import {
getProjects,
getWorkspaceLayout,
joinPathFragments,
logger,
names,
normalizePath,
Tree,
Expand Down Expand Up @@ -36,12 +37,27 @@ export function normalizeOptions(
const importPath =
options.importPath || getImportPath(npmScope, fullProjectDirectory);

let bundler = options.bundler ?? 'none';

if (bundler === 'none') {
if (options.publishable) {
logger.warn(
`Publishable libraries cannot be used with bundler: 'none'. Defaulting to 'rollup'.`
);
bundler = 'rollup';
}
if (options.buildable) {
logger.warn(
`Buildable libraries cannot be used with bundler: 'none'. Defaulting to 'rollup'.`
);
bundler = 'rollup';
}
}

const normalized = {
...options,
compiler: options.compiler ?? 'babel',
bundler:
options.bundler ??
(options.buildable || options.publishable ? 'rollup' : 'none'),
bundler,
fileName,
routePath: `/${name}`,
name: projectName,
Expand Down

0 comments on commit 99983e9

Please sign in to comment.