Skip to content

Commit

Permalink
resolve styled components as a CJS module
Browse files Browse the repository at this point in the history
  • Loading branch information
shlokamin committed Nov 26, 2024
1 parent e73702d commit 04283ec
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions components/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,24 @@ export default defineConfig({
lib: {
entry: 'src/index.ts',
formats: ['es', 'cjs'], // Generate both ES Module and CommonJS outputs
fileName: (format) => (format === 'es' ? 'index.mjs' : 'index.cjs'),
fileName: format => (format === 'es' ? 'index.mjs' : 'index.cjs'),
},
rollupOptions: {
external: ['react', 'react-dom', 'styled-components'], // Ensure peer dependencies are not bundled
external: ['react', 'react-dom', 'styled-components'], // Externalize peer dependencies
output: {
exports: 'named',
globals: {
'styled-components': 'styled', // Use 'styled' as the global variable name
},
plugins: [
require('@rollup/plugin-commonjs')({
include: /node_modules/,
namedExports: {
'styled-components': ['default'], // Ensure default export is correctly mapped
},
}),
],
},
},
target: 'es2017', // Transpile down to a compatible version for Next.js (for Protocol Library)
},
Expand Down

0 comments on commit 04283ec

Please sign in to comment.