previewjs icon indicating copy to clipboard operation
previewjs copied to clipboard

Support global vars injected by webpack.DefinePlugin

Open wilomgfx opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe. I'm getting undefined errors from some of my code that uses global vars defined with webpack.DefinePlugin https://webpack.js.org/plugins/define-plugin/

Describe the solution you'd like I want my vars to be loaded from the Wrapper component.

Describe alternatives you've considered Manually set up the vars, but that would be cumbersome and add code duplication.

Additional context None

wilomgfx avatar Oct 07 '21 15:10 wilomgfx

Hi @wilomgfx, you might be able to make it work with the following in reactpreview.config.js:

const reactpreview = require("@reactpreview/config");

module.exports = reactpreview.config({
  vite: {
    define: {
      // ...
    }
  }
});

See https://vitejs.dev/config/#define for the corresponding Vite documentation.

I haven't tried this myself so not entirely sure whether this will work :) Let me know how you go!

fwouts avatar Oct 09 '21 05:10 fwouts

Hi @wilomgfx, you might be able to make it work with the following in reactpreview.config.js:

const reactpreview = require("@reactpreview/config");

module.exports = reactpreview.config({
  vite: {
    define: {
      // ...
    }
  }
});

See vitejs.dev/config/#define for the corresponding Vite documentation.

I haven't tried this myself so not entirely sure whether this will work :) Let me know how you go!

Hi,

Thanks for your response.

I will try it out this week and get back to you :)!

wilomgfx avatar Oct 12 '21 18:10 wilomgfx