Skip to content

chore: preserve modules and outdir #5191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ target
**/build
**/node_modules
**/coverage
**/.yalc
**/yalc.lock

**/.vs
**/.vscode
Expand Down
1 change: 0 additions & 1 deletion react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"scripts": {
"build": "vite build",
"build:watch": "vite build --watch",
"build:watch:yalc": "YALC=true vite build --watch",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build --test",
"tsc": "tsc",
Expand Down
125 changes: 50 additions & 75 deletions react-components/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,86 +1,61 @@
import { resolve } from 'path';
import { type PluginOption, defineConfig } from 'vite';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import dts from 'vite-plugin-dts';
import { externalizeDeps } from 'vite-plugin-externalize-deps';
import { exec } from 'node:child_process';
import { coverageConfigDefaults } from 'vitest/config';

export default defineConfig(({ command }) => {
return {
plugins: [
react(),
dts({ tsconfigPath: './tsconfig.build.json' }),
externalizeDeps({
devDeps: true
}),
yalcPush()
],
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(__dirname, 'src/index.ts'),
name: 'Reveal react components',
// the proper extensions will be added
fileName: 'index',
formats: ['es']
},
sourcemap: command === 'build'
export default defineConfig(({ command }) => ({
plugins: [
react(),
dts({ tsconfigPath: './tsconfig.build.json' }),
externalizeDeps({
devDeps: true
})
],
build: {
emptyOutDir: false,
lib: {
entry: resolve(__dirname, 'src/index.ts'),
fileName: '[name]',
formats: ['es']
},
test: {
mockReset: true,
include: ['src/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
environment: 'happy-dom',
globals: true,
reporters: ['default'],
coverage: {
reportsDirectory: '../coverage/reveal-react-components',
exclude: [
...coverageConfigDefaults.exclude,
'src/**/*.spec.ts',
'src/**/*.spec.tsx',
'src/**/*.test.ts',
'src/**/*.test.tsx',
'stories/**'
rollupOptions: {
output: {
preserveModules: true
}
},
sourcemap: command === 'build'
},
test: {
mockReset: true,
include: ['src/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
environment: 'happy-dom',
globals: true,
reporters: ['default'],
coverage: {
reportsDirectory: '../coverage/reveal-react-components',
exclude: [
...coverageConfigDefaults.exclude,
'src/**/*.spec.ts',
'src/**/*.spec.tsx',
'src/**/*.test.ts',
'src/**/*.test.tsx',
'stories/**'
]
},
// Need to add E5 modules as inlined dependencies to be able to import them in tests.
server: {
deps: {
inline: [
'@cognite/cogs-lab',
'@cognite/cogs.js',
'@cognite/cogs-core',
'@mui',
'@cognite/cogs-utils',
'lodash'
]
},
// Need to add E5 modules as inlined dependencies to be able to import them in tests.
server: {
deps: {
inline: [
'@cognite/cogs-lab',
'@cognite/cogs.js',
'@cognite/cogs-core',
'@mui',
'@cognite/cogs-utils',
'lodash'
]
}
}
}
};
});

function yalcPush(): PluginOption {
if (process.env.YALC !== 'true') {
return false;
}
return {
name: 'yalc-push',
closeBundle: async () => {
await new Promise<void>((resolve, reject) => {
const process = exec('yalc push');
process.stdout
?.on('data', (data) => {
console.log(data);
})
.on('error', (err) => {
reject(err);
})
.on('close', () => {
resolve();
});
});
}
};
}
}));
Loading