Skip to content

Commit

Permalink
fix(react): add bundler to create-nx-workspace react preset so webpac…
Browse files Browse the repository at this point in the history
…k package is installed
  • Loading branch information
jaysoo committed Jan 23, 2023
1 parent c6adec7 commit 0ab8ad5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions e2e/workspace-create/src/create-nx-workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
expectNoTsJestInJestConfig,
getSelectedPackageManager,
packageManagerLockFile,
readJson,
runCreateWorkspace,
uniq,
} from '@nrwl/e2e/utils';
Expand Down Expand Up @@ -126,10 +127,13 @@ describe('create-nx-workspace', () => {
style: 'css',
appName,
packageManager,
bundler: 'webpack',
});

expectNoAngularDevkit();
expectNoTsJestInJestConfig(appName);
const packageJson = readJson('package.json');
expect(packageJson.devDependencies['@nrwl/webpack']).toBeDefined();
});

it('should be able to create an next workspace', () => {
Expand Down
8 changes: 5 additions & 3 deletions packages/cra-to-nx/src/lib/cra-to-nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,11 @@ function createTempWorkspace(options: NormalizedOptions) {
options.npxYesFlagNeeded ? '-y' : ''
} create-nx-workspace@latest temp-workspace --appName=${
options.reactAppName
} --preset=react-monorepo --style=css --packageManager=${
options.packageManager
} ${options.nxCloud ? '--nxCloud' : '--nxCloud=false'}`,
} --preset=react-monorepo --style=css --bundler=${
options.isVite ? 'vite' : 'webpack'
} --packageManager=${options.packageManager} ${
options.nxCloud ? '--nxCloud' : '--nxCloud=false'
}`,
{ stdio: [0, 1, 2] }
);

Expand Down
2 changes: 1 addition & 1 deletion packages/cra-to-nx/src/lib/write-craco-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function writeCracoConfig(
new TsConfigPathsPlugin({
configFile: path.resolve(__dirname, 'tsconfig.json'),
extensions: ['.ts', '.tsx', '.js', '.jsx'],
mainFields: ['module', 'main'],
mainFields: ['browser', 'module', 'main'],
})
);
${
Expand Down
4 changes: 4 additions & 0 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ async function getConfiguration(
} else {
name = await determineRepoName(argv);
appName = await determineAppName(preset, argv);
if (preset === Preset.ReactMonorepo) {
bundler = await determineBundler(argv);
}
}
style = await determineStyle(preset, argv);
}
Expand Down Expand Up @@ -1009,6 +1012,7 @@ async function createSandbox(packageManager: PackageManager) {

return tmpDir;
}

async function createApp(
tmpDir: string,
name: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack/src/utils/with-nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const IGNORED_WEBPACK_WARNINGS = [
];

const extensions = ['.ts', '.tsx', '.mjs', '.js', '.jsx'];
const mainFields = ['main', 'module'];
const mainFields = ['browser', 'main', 'module'];

const processed = new Set();

Expand Down
1 change: 1 addition & 0 deletions packages/workspace/src/generators/preset/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ async function createPreset(tree: Tree, options: Schema) {
style: options.style,
linter: options.linter,
standaloneConfig: options.standaloneConfig,
bundler: options.bundler ?? 'webpack',
});
} else if (options.preset === Preset.ReactStandalone) {
const {
Expand Down

0 comments on commit 0ab8ad5

Please sign in to comment.