javascript - Webpack DefinePlugin från async-funktion
Jag skulle vilja definiera några konstanter som returneras från en asynkron resurs. Finns det något sätt att göra detta i Webpack?
/* webpack.config.js */
module.exports = {
...,
plugins: [
new webpack.DefinePlugin({
someVar: /* RETURN VARIABLE FROM ASYNC FUNCTION */
})
]
}
Svar #1
Ett bra sätt att göra detta är att returnera ett Promise från webpack-konfigurationen.
webpack.config.js
...
module.exports = () => {
return getYourAsyncResource().then((someVar) => {
// Resolve as webpack configuration
return {
...
plugins: [
new webpack.DefinePlugin({ someVar })
]
};
})
};
