Is it possible to tell Webpack to ignore/remove the import fetch from "cross-fetch"
import statement since the variable fetch
already exists in the global namespace?
import fetch from "cross-fetch";
Is it possible to tell Webpack to ignore/remove the import fetch from "cross-fetch"
import statement since the variable fetch
already exists in the global namespace?
import fetch from "cross-fetch";
Yes, you can tell Webpack to ignore/remove the import fetch from "cross-fetch"
import statement by adding the following configuration to your webpack.config.js file:
module.exports = {
//...
plugins: [
new webpack.ProvidePlugin({
fetch: 'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch'
})
]
};
This configuration tells Webpack to provide the global fetch
variable, which already exists in the global namespace, to any module that imports fetch
from the cross-fetch
package.