Skip to content
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

Support decorators in JS files #60

Closed
meetajhu opened this issue Feb 19, 2023 · 3 comments
Closed

Support decorators in JS files #60

meetajhu opened this issue Feb 19, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@meetajhu
Copy link

meetajhu commented Feb 19, 2023

I went through the docs/issues and there is a no clear way on how to add decorator support for Mobx or is it even supported? I am not using Typescript.

From this docs i tried passing like this in below config:

import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react-swc'
import svgrPlugin from 'vite-plugin-svgr';
import { splitVendorChunkPlugin } from 'vite';
import * as path from 'path';
import jsconfigPaths from 'vite-jsconfig-paths'
import { createHtmlPlugin } from 'vite-plugin-html'

export default defineConfig(({ mode }) => {

  const env = loadEnv(mode, process.cwd())

  return {
    plugins: [react(
      {
          "decorators": true,
          "decoratorsBeforeExport": true,
      }
    ), svgrPlugin(), jsconfigPaths(), splitVendorChunkPlugin(),
    createHtmlPlugin({
      minify: true,
      inject: {
        data: {
          reactenv: env.REACT_APP_ACTUAL_ENV,
        }
      }
    })
  ],
  define: { //Handle prcoess.env
    'process.env': {}
  },
  }});

i keep getting error in console this.example is undefined

@ArnaudBarre ArnaudBarre added the enhancement New feature or request label Feb 19, 2023
@ArnaudBarre ArnaudBarre changed the title [CRA -> Vite] How to add decorator support using plugin-react-swc(js module) Support decorators is JS files Feb 19, 2023
@ArnaudBarre
Copy link
Member

Yes this is not supported ATM. JS files are sent untranspiled in dev to the browser and this feature is not supported by esbuild. This is technically possible to add support for this, but I'm not sure this is a good idea.
This should be possible with the Babel plugin

@meetajhu meetajhu changed the title Support decorators is JS files Support decorators in JS files Feb 19, 2023
@ArnaudBarre
Copy link
Member

Hi!
I discussed this with the team and for now we like the fact that pure JS code is sent unstranspiled to the browser in dev mode. If your codebase is small the babel plugin will probably be as fast as the SWC one. And if for large codebases, I really invite you to migrate to TS, this is really worth the initial learning curve in the long run.

@ArnaudBarre ArnaudBarre closed this as not planned Won't fix, can't repro, duplicate, stale Mar 26, 2023
@meetajhu
Copy link
Author

meetajhu commented Apr 5, 2023

Hi! I discussed this with the team and for now we like the fact that pure JS code is sent unstranspiled to the browser in dev mode. If your codebase is small the babel plugin will probably be as fast as the SWC one. And if for large codebases, I really invite you to migrate to TS, this is really worth the initial learning curve in the long run.

Yup its a large one. Sure will work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants