vite
vite copied to clipboard
Allow preview mode for libraries
Clear and concise description of the problem
I am building a web SDK.
I used the lib mode to configure my outputs.
I am developing the library in esm
and my library is gonna be served in cjs
. In order to make sure it's working (tests and manually) I need to copy/create index.html file and reference the output script (vite does it on regular mode OOO).
Suggested solution
Therefore I want to allow 'lib preview' let me explain:
- Developer run
yarn vite preview
- Preview server is starting (same as today), but it copies the HTML file to the dist and do the following (this piece of code I wrote in a vite plugin)
transformIndexHtml: async (htmlString) => {
const htmlStringWithScript = htmlString.replace(
`<script type="module" src="./src/index.ts"></script>`,
`<script src="sdk.cjs.js"></script>`,
);
return htmlStringWithScript;
},
Alternative
Allow configuring 'preview' options to serve libraries
Additional context
I am also willing to contribute and open PR, if the authors will see this feature as meaningful to the platform
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.