Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom react-scripts packages #4712

Merged
merged 3 commits into from
Nov 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions app/react/src/server/cra_config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import fs from 'fs';
import path from 'path';
import semver from 'semver';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';

import { normalizeCondition } from 'webpack/lib/RuleSet';

let reactScriptsPath;
function getReactScriptsPath() {
if (reactScriptsPath) return reactScriptsPath;
const appDirectory = fs.realpathSync(process.cwd());
const reactScriptsScriptPath = fs.realpathSync(
path.join(appDirectory, '/node_modules/.bin/react-scripts')
);
reactScriptsPath = path.join(reactScriptsScriptPath, '../..');
return reactScriptsPath;
}

export function isReactScriptsInstalled() {
try {
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
const reactScriptsJson = require('react-scripts/package.json');
// eslint-disable-next-line global-require, import/no-dynamic-require
const reactScriptsJson = require(path.join(getReactScriptsPath(), 'package.json'));
if (semver.lt(reactScriptsJson.version, '2.0.0')) return false;
return true;
} catch (e) {
Expand Down Expand Up @@ -42,12 +55,12 @@ export function getStyleRules(rules) {

export function getCraWebpackConfig(mode) {
if (mode === 'production') {
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
return require('react-scripts/config/webpack.config.prod');
// eslint-disable-next-line global-require, import/no-dynamic-require
return require(path.join(getReactScriptsPath(), 'config/webpack.config.prod'));
}

// eslint-disable-next-line global-require, import/no-extraneous-dependencies
return require('react-scripts/config/webpack.config.dev');
// eslint-disable-next-line global-require, import/no-dynamic-require
return require(path.join(getReactScriptsPath(), 'config/webpack.config.dev'));
}

export function applyCRAWebpackConfig(baseConfig) {
Expand Down