Skip to content

Commit

Permalink
build(env): use vercel env vars to determin environment (#2016)
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenOutman committed Oct 20, 2021
1 parent e0bbc45 commit 6e469c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = (api, options) => {
const { NODE_ENV, ALIAS = 'locally' } = options || process.env;
const { NODE_ENV, VERCEL_ENV = 'local' } = options || process.env;

if (api) {
api.cache(() => NODE_ENV);
Expand Down Expand Up @@ -42,7 +42,7 @@ module.exports = (api, options) => {
'@': './'
};

if (ALIAS === 'locally') {
if (VERCEL_ENV === 'preview' || VERCEL_ENV === 'local') {
alias.rsuite = '../src';
}

Expand Down
17 changes: 13 additions & 4 deletions docs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ const markdownRenderer = require('./scripts/markdownRenderer');
const resolveToStaticPath = relativePath => path.resolve(__dirname, relativePath);
const SVG_LOGO_PATH = resolveToStaticPath('./resources/images');
const __DEV__ = process.env.NODE_ENV !== 'production';
const __LOCAL__ = process.env.ALIAS === 'locally';

const {
// 'production' on main branch
// 'preview' on pr branches
// emtpy on local machine
// @see https://vercel.com/docs/concepts/projects/environment-variables#system-environment-variables
VERCEL_ENV = 'local'
} = process.env;

const __USE_SRC__ = VERCEL_ENV === 'preview' || VERCEL_ENV === 'local';

const RSUITE_ROOT = path.join(__dirname, '../src');
const LANGUAGES = {
Expand All @@ -21,7 +30,7 @@ const LANGUAGES = {
};

const getLanguage = language => LANGUAGES[language] || '';
const babelBuildInclude = __LOCAL__
const babelBuildInclude = __USE_SRC__
? [RSUITE_ROOT, path.join(__dirname, './')]
: [path.join(__dirname, './')];

Expand Down Expand Up @@ -89,7 +98,7 @@ module.exports = {
sourceMap: true,
lessOptions: {
globalVars: {
rootPath: __LOCAL__ ? '../../../src/' : '~rsuite'
rootPath: __USE_SRC__ ? '../../../src/' : '~rsuite'
}
}
}
Expand Down Expand Up @@ -162,7 +171,7 @@ module.exports = {

// If we are building docs with local rsuite from src (local development and review builds),
// we should target `react` and `react-dom` imports to root node_modules
if (__LOCAL__) {
if (__USE_SRC__) {
Object.assign(config.resolve.alias, {
react: path.resolve(__dirname, '../node_modules/react'),
'react-dom': path.resolve(__dirname, '../node_modules/react-dom')
Expand Down
6 changes: 3 additions & 3 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"scripts": {
"check:type": "tsc",
"clear": "rimraf ./.next && rimraf ./out ",
"dev": "cross-env NODE_ENV=development ALIAS=locally node server.js",
"dev": "cross-env NODE_ENV=development node server.js",
"dev:styles": "cross-env STYLE_DEBUG=STYLE npm run dev",
"build": "npm run clear && ALIAS=locally next build && next export",
"build:docker": "ALIAS=rsuite next build",
"build": "npm run clear && next build && next export",
"build:docker": "next build",
"build:next": "NODE_OPTIONS=--max_old_space_size=8192 next build",
"build:export": "next export",
"start": "cross-env NODE_ENV=production node server.js",
Expand Down

1 comment on commit 6e469c5

@vercel
Copy link

@vercel vercel bot commented on 6e469c5 Oct 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.