Skip to content

Commit

Permalink
fix(react): point output to correct location
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Dec 4, 2024
1 parent b294f1e commit 7e328e5
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
readNxJson,
readProjectConfiguration,
runTasksInSerial,
stripIndents,
updateProjectConfiguration,
} from '@nx/devkit';

Expand Down Expand Up @@ -76,11 +75,15 @@ const svg = require('@svgr/rollup');
module.exports = withNx({
main: '${maybeJs(options, './src/index.ts')}',
outputPath: '${joinPathFragments(
offsetFromRoot(options.projectRoot),
'dist',
options.projectRoot
)}',
outputPath: '${
options.isUsingTsSolutionConfig
? './dist'
: joinPathFragments(
offsetFromRoot(options.projectRoot),
'dist',
options.projectRoot
)
}',
tsConfig: './tsconfig.lib.json',
compiler: '${options.compiler ?? 'babel'}',
external: ${JSON.stringify(external)},
Expand Down
93 changes: 93 additions & 0 deletions packages/react/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,59 @@ module.exports = withNx(
name: 'mylib',
});

expect(tree.read('mylib/vite.config.ts', 'utf-8')).toMatchInlineSnapshot(`
"/// <reference types='vitest' />
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import dts from 'vite-plugin-dts';
import * as path from 'path';
export default defineConfig({
root: __dirname,
cacheDir: '../node_modules/.vite/mylib',
plugins: [react(), dts({ entryRoot: 'src', tsconfigPath: path.join(__dirname, 'tsconfig.lib.json') })],
// Uncomment this if you are using workers.
// worker: {
// plugins: [ nxViteTsPaths() ],
// },
// Configuration for building your library.
// See: https://vitejs.dev/guide/build.html#library-mode
build: {
outDir: './dist',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
},
lib: {
// Could also be a dictionary or array of multiple entry points.
entry: 'src/index.ts',
name: 'mylib',
fileName: 'index',
// Change this to the formats you want to support.
// Don't forget to update your package.json as well.
formats: ['es', 'cjs']
},
rollupOptions: {
// External packages that should not be bundled into your library.
external: ['react','react-dom','react/jsx-runtime']
},
},
test: {
watch: false,
globals: true,
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
reporters: ['default'],
coverage: {
reportsDirectory: '../coverage/mylib',
provider: 'v8',
}
},
});
"
`);

expect(readJson(tree, 'tsconfig.json').references).toMatchInlineSnapshot(`
[
{
Expand Down Expand Up @@ -1089,5 +1142,45 @@ module.exports = withNx(
}
`);
});

it('should configure rollup correctly', async () => {
await libraryGenerator(tree, {
...defaultSchema,
bundler: 'rollup',
unitTestRunner: 'none',
directory: 'mylib',
name: 'mylib',
});

expect(tree.read('mylib/rollup.config.cjs', 'utf-8'))
.toMatchInlineSnapshot(`
"const { withNx } = require('@nx/rollup/with-nx');
const url = require('@rollup/plugin-url');
const svg = require('@svgr/rollup');
module.exports = withNx({
main: './src/index.ts',
outputPath: './dist',
tsConfig: './tsconfig.lib.json',
compiler: 'babel',
external: ["react","react-dom","react/jsx-runtime"],
format: ['esm'],
assets:[{ input: '.', output: '.', glob: 'README.md'}],
}, {
// Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
plugins: [
svg({
svgo: false,
titleProp: true,
ref: true,
}),
url({
limit: 10000, // 10kB
}),
],
});
"
`);
});
});
});

0 comments on commit 7e328e5

Please sign in to comment.