Reputation: 25890
When packaging our Node.js application, we change some underlying folder structure, so the paths need to be adjusted at run-time, and the app simply needs to know whether or not it was packaged via webpack.
What is the easiest/best approach with Webpack to tell a Node.js app that it was packaged?
Upvotes: 0
Views: 84
Reputation: 25890
This worked well eventually...
In webpack.config.js
:
plugins: [
new webpack.DefinePlugin({
PACKAGED: true
})
And then in the Node.js code:
function isPackaged() {
return typeof PACKAGED !== 'undefined' && !!PACKAGED;
}
During packaging, webpack replaces such code with:
function isPackaged() {
return "boolean" !== 'undefined' && !!true;
}
So we get false
when running unpackaged code, and true
after it was packaged.
Upvotes: 1