onebay / vite-plugin-imp

A vite plugin for import library component style automatic.
MIT License
232 stars 24 forks source link

What about always transform no matter "serve" or "build" #92

Closed justforuse closed 1 year ago

justforuse commented 1 year ago

Describe the bug

Thanks your work, it is a helpful package

Does this plugin only work under "build"? It maybe useful under development, Or we can add a option, to let user whether always transform the import declaration

Libarary Info(please complete the following information): Libarary: [name]

To Reproduce Steps to reproduce the behavior:
Paste your code here or provide a minimal reproduce repo link.

Expected behavior A clear and concise description of what you expected to happen.

Error message Paste the error message here.

Additional context Add any other context about the problem here.

psaren commented 1 year ago

You can just comment out the code for this plugin. Another way is using the process.env.NODE_ENV

plugins: [
    react(), 
    process.env.NODE_ENV === 'production' ? vitePluginImp() : null
  ].filter(Boolean),
justforuse commented 1 year ago
return {
  code: `${importStr};${viteConfig.command === 'serve' ? code : codeRemoveOriginImport}`,
  map: isSourcemap ? sourcemap : null
}

Let's clear what I mean. In this code, I want to it return codeRemoveOriginImport no matter what the viteConfig.command is. so I can get better experience under local development both serve and build

And the code like this

return {
  code: `${importStr};${(options.always || viteConfig.command === 'serve') ? code : codeRemoveOriginImport}`,
  map: isSourcemap ? sourcemap : null
}
psaren commented 1 year ago

In order to be compatible with previous versions, this ability needs to be enabled by the developer Now you can open this in V2.4.0

vitePluginImp({
   removeOriginImport: true
}),