7

Any idea how i can convert this highlighted require statement to the import/export syntax? Or is it not possible?

I have two different config files for webpack dev and prod, so i need to return the correct config file in webpack.config.js.

Thanks a million! :D

Comments
  • 0
    Dynamic imports isn't available without extra Babel plugin. Perhaps something like this https://github.com/airbnb/...

    Looks kinda bad practice anyways. Any specific reason for doing it this way? You can't import JSON instead?

    Btw, welcome! And good use of categories there :)
  • 2
    Hi @ScriptCoded! I copied the code from https://hacksoft.io/blog/... and it makes sense to do dynamic imports in this case so...

    Ctrl-C Ctrl-V

    Then I wanted to upgrade from require() to import/export cause vscode is giving me this warning that I should upgrade to import/export. Using require in this return statement does not give the warning tho.

    Bye I don't think I can use Babel plugins here, since this is a webpack config file. Thanks for your reply and have a nice day ahead, wherever you may be :)
  • 1
    why not have 2 config files? the documentation suggest having one webpack.common.js and two other: webpack.dev.js and config.prod.js, you would use webpack merge to merge the data from the webpack.common.js with the webpack.dev.js and webpack.prod.js

    have a look here:

    https://webpack.js.org/guides/...
  • 1
    @echonox Thanks! Will take a look at that :>
  • 0
    @justarandomuser You're probably using Babel since you're writing ES6. You're using node, right?
  • 2
    @ScriptCoded I am using node, but I plan to use babel as a loader for webpack
  • 0
    @justarandomuser Then you can't be using import without Babel. It has to be transpiled
  • 6
    @ScriptCoded Okay, thanks a lot everyone! Looks like I'll stick to require() for now and use @echonox solution!
  • 1
    Working with converter is not just I tell you. Handling file conversions from PDF or images to Excel, Google Sheets, or CSV is a frequent challenge in my work, and I'm not well-versed in it. Luckily, Secure Statement Converter https://securestatementconverter.com/... comes to my rescue. Just thanks to this tool, my documents are well-organized and in order.
  • 0
    Of course! I can assist with the import/export syntax if you give me the exact require statement that you want to convert.
Add Comment