LoginSignup
1
0

More than 5 years have passed since last update.

Serverless Webpackでオプションの値を受け取る

Posted at
$ sls deploy --stage=staging

みたいな感じでビルド時に渡したオプションをWebpack側でも受け取って使いたいなーと思って調べてたら案外簡単だったのでメモ。

webpack.config.jsで下記のコードを書けば受け取れる。

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

あとはオプションの値に合わせて、DefinePluginとかで設定してやれば良い。

  plugins: [
    new webpack.DefinePlugin({
      HOGE: JSON.stringify(SETTINGS[stage])
    })
  ]
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0