-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
24 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,28 @@ | ||
import react from '@vitejs/plugin-react'; | ||
import fs from 'fs'; | ||
import { resolve } from 'path'; | ||
import tailwindcss from 'tailwindcss'; | ||
import { defineConfig } from 'vite'; | ||
import dts from 'vite-plugin-dts'; | ||
|
||
function inlineSvg(...paths) { | ||
return { | ||
name: 'inline-svg', | ||
transformIndexHtml: { | ||
enforce: 'pre', | ||
transform: (html) => { | ||
if (!Array.isArray(paths) || paths.length <= 0) return html; | ||
|
||
let newHtml = html; | ||
paths.forEach((svg) => { | ||
const extractedSvg = fs.readFileSync(svg, 'utf8'); | ||
newHtml = newHtml.replace('<body>', `<body>${extractedSvg}`); | ||
}); | ||
return newHtml; | ||
}, | ||
export default defineConfig({ | ||
server: { open: false }, | ||
plugins: [react(), dts({ rollupTypes: true })], | ||
css: { | ||
postcss: { | ||
plugins: [tailwindcss], | ||
}, | ||
}; | ||
} | ||
|
||
export default defineConfig(({ isSsrBuild, isPreview }) => { | ||
const isLadle = isSsrBuild === undefined && isPreview === undefined; | ||
|
||
return { | ||
server: { open: false }, | ||
plugins: isLadle | ||
? [inlineSvg('src/assets/icons.svg', '.ladle/assets/stories-icons.svg')] | ||
: [react(), dts({ rollupTypes: true })], | ||
css: { | ||
postcss: { | ||
plugins: [tailwindcss], | ||
}, | ||
}, | ||
build: { | ||
lib: { | ||
entry: resolve(__dirname, 'src/index.ts'), | ||
name: '@e-krebs/react-library', | ||
fileName: 'index', | ||
}, | ||
build: { | ||
lib: { | ||
entry: resolve(__dirname, 'src/index.ts'), | ||
name: '@e-krebs/react-library', | ||
fileName: 'index', | ||
}, | ||
rollupOptions: { | ||
external: ['react', 'react-dom', 'tailwindcss'], | ||
output: { globals: { react: 'React', 'react-dom': 'ReactDOM', tailwindcss: 'tailwindcss' } }, | ||
}, | ||
sourcemap: true, | ||
emptyOutDir: true, | ||
rollupOptions: { | ||
external: ['react', 'react-dom', 'tailwindcss'], | ||
output: { globals: { react: 'React', 'react-dom': 'ReactDOM', tailwindcss: 'tailwindcss' } }, | ||
}, | ||
}; | ||
sourcemap: true, | ||
emptyOutDir: true, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
} | ||
} |