Skip to content

Commit

Permalink
feat(cli): setup define webpack plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mediremi authored and KaiVandivier committed Aug 23, 2022
1 parent 202225c commit 5d8f374
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cli/src/lib/plugin/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent')
const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath')
const webpack = require('webpack')
const makeBabelConfig = require('../../../config/makeBabelConfig')
const getShellEnv = require('../shell/env')

const babelWebpackConfig = {
babelrc: false,
Expand All @@ -26,6 +28,8 @@ module.exports = ({ env: webpackEnv, paths }) => {
process.env.PUBLIC_URL
)

const shellEnv = getShellEnv({})

// "style" loader turns CSS into JS modules that inject <style> tags.
// "css" loader resolves paths in CSS and adds assets as dependencies.
// "postcss" loader applies autoprefixer to our CSS.
Expand Down Expand Up @@ -116,6 +120,20 @@ module.exports = ({ env: webpackEnv, paths }) => {
chunkFilename:
'static/css/[name].[contenthash:8].chunk.css',
}),
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === 'production') { ... }.
// It is absolutely essential that NODE_ENV is set to production
// during a production build.
// Otherwise React will be compiled in the very slow development mode.
new webpack.DefinePlugin({
'process.env': {
...Object.keys(shellEnv).reduce((env, key) => {
env[key] = JSON.stringify(shellEnv[key])
return env
}, {}),
NODE_ENV: JSON.stringify(webpackEnv),
},
}),
],
module: {
rules: [
Expand Down

0 comments on commit 5d8f374

Please sign in to comment.