I want to set environment variable for internal webpack plugin
How can I set an environment variable for the WebStorm's webpack plugin? I need to specify it to get the right webpack config to resolve files.
My use case:
I have files with different suffixes like Item.target1.js, Item.target2.js for different targets. In my project, I load dependencies with ES6 syntax like:
import Item from "./Item";
I use webpack to bundle sources. This is achieved with specifying configuration property (resolve.extensions = ["js", `.${process.env.TARGET}.js`] ). Also, I use eslint configuration with eslint-plugin-import, eslint-import-resolver-webpack plugins to get these extensions from webpack configuration. The only thing is required is to have a possibility to set this variable in the internal process/terminal, which resolves my webpack configuration for WebStorm itself. In such, case I would be able to navigate inside WebStorm based on my current target.
I hope I explained well enough. Please ask if you have other questions.
Please sign in to leave a comment.
Setting variables won't help, WebStorm won't use them when resolving your imports, sorry.
Webpack resolve.extensions is not supported (only resolve.roots (webpack 1), resolve.module_directories (webpack 1), resolve.modules (webpack 2), resolve.alias (webpack 1/2) are). And, even if the support is added one day, you can hardly expect it to work for dynamically generated extensions
For resolve.extensions support, please, vote for https://youtrack.jetbrains.com/issue/WEB-26330