Serverless-webpack: Get environment/stage in webpack.config.js?

Created on 11 Dec 2017  路  2Comments  路  Source: serverless-heaven/serverless-webpack

Is it possible to retrieve the serverless stage or environment in webpack.config.js, or to load different config files for different environments?

When I add this to webpack.config.js:

console.log(`bundling with webpack for environment ${process.env.NODE_ENV}`)

It turns out that NODE_ENV is undefined.

Most helpful comment

Hi @tommedema ,
you can retrieve the serverless stage within the webpack config:

const slsw = require('serverless-webpack');
const stage = slsw.lib.options.stage;

// You also have access to the whole Serverless service object too:
const serverless = slsw.lib.serverless;

So, in fact, you can access anything that is available in the serverless instance,
just like any plugin.

All 2 comments

Hi @tommedema ,
you can retrieve the serverless stage within the webpack config:

const slsw = require('serverless-webpack');
const stage = slsw.lib.options.stage;

// You also have access to the whole Serverless service object too:
const serverless = slsw.lib.serverless;

So, in fact, you can access anything that is available in the serverless instance,
just like any plugin.

Excellent!

Was this page helpful?
0 / 5 - 0 ratings