Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !206

eliminate dev-only code on eject #53 #191

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/Jiansen/clean-eject into master 8 years ago
  • Overview 11
  • Commits 2
  • Pipelines 0
  • Changes 3

Created by: Jiansen

// Dead code on eject: start
dev-only code
// Dead code on eject: end

will be removed when the scripts are exposed to users on eject

npm pack copies all files to the created package. To adopt the approach proposed in #191 and give a clean code in the published package , we may need to temporary add files to .npmignore before npm, similar to what we do to package.json code link

Compare
  • master (base)

and
  • latest version
    8277f213
    2 commits, 2 years ago

3 files
+ 13
- 5

    Preferences

    File browser
    Compare changes
con‎fig‎
path‎s.js‎ +8 -4
scr‎ipts‎
ejec‎t.js‎ +2 -0
star‎t.js‎ +3 -1
config/paths.js
+ 8
- 4
  • View file @ 8277f213


@@ -12,6 +12,11 @@
@@ -12,6 +12,11 @@
var path = require('path');
var path = require('path');
 
function resolve(relativePath) {
 
return path.resolve(__dirname, relativePath);
 
}
 
 
// Dead code on eject: start
// True when used as a dependency, false after ejecting
// True when used as a dependency, false after ejecting
var isInNodeModules = (
var isInNodeModules = (
'node_modules' ===
'node_modules' ===
@@ -23,10 +28,6 @@ var isInCreateReactAppSource = (
@@ -23,10 +28,6 @@ var isInCreateReactAppSource = (
process.argv.some(arg => arg.indexOf('--debug-template') > -1)
process.argv.some(arg => arg.indexOf('--debug-template') > -1)
);
);
function resolve(relativePath) {
return path.resolve(__dirname, relativePath);
}
if (isInCreateReactAppSource) {
if (isInCreateReactAppSource) {
// create-react-app development: we're in ./config/
// create-react-app development: we're in ./config/
module.exports = {
module.exports = {
@@ -52,6 +53,7 @@ if (isInCreateReactAppSource) {
@@ -52,6 +53,7 @@ if (isInCreateReactAppSource) {
};
};
} else {
} else {
// after eject: we're in ./config/
// after eject: we're in ./config/
 
// Dead code on eject: end
module.exports = {
module.exports = {
appBuild: resolve('../build'),
appBuild: resolve('../build'),
appHtml: resolve('../index.html'),
appHtml: resolve('../index.html'),
@@ -61,4 +63,6 @@ if (isInCreateReactAppSource) {
@@ -61,4 +63,6 @@ if (isInCreateReactAppSource) {
appNodeModules: resolve('../node_modules'),
appNodeModules: resolve('../node_modules'),
ownNodeModules: resolve('../node_modules')
ownNodeModules: resolve('../node_modules')
};
};
 
// Dead code on eject: start
}
}
 
// Dead code on eject: end
scripts/eject.js
+ 2
- 0
  • View file @ 8277f213


@@ -80,6 +80,8 @@ prompt('Are you sure you want to eject? This action is permanent. [y/N]', functi
@@ -80,6 +80,8 @@ prompt('Are you sure you want to eject? This action is permanent. [y/N]', functi
.replace(/^\/\*\*(\*(?!\/)|[^*])*\*\//, '')
.replace(/^\/\*\*(\*(?!\/)|[^*])*\*\//, '')
// Remove license header from AppleScript
// Remove license header from AppleScript
.replace(/^--.*\n/gm, '')
.replace(/^--.*\n/gm, '')
 
// Remove dead code on eject
 
.replace(/\/\/ Dead code on eject: start([\s\S]*?)\/\/ Dead code on eject: end/g, '')
.trim() + '\n';
.trim() + '\n';
fs.writeFileSync(path.join(appPath, file), content);
fs.writeFileSync(path.join(appPath, file), content);
});
});
scripts/start.js
+ 3
- 1
  • View file @ 8277f213


@@ -17,9 +17,10 @@ var config = require('../config/webpack.config.dev');
@@ -17,9 +17,10 @@ var config = require('../config/webpack.config.dev');
var execSync = require('child_process').execSync;
var execSync = require('child_process').execSync;
var opn = require('opn');
var opn = require('opn');
// TODO: hide this behind a flag and eliminate dead code on eject.
// hide this behind a flag and eliminate dead code on eject.
// This shouldn't be exposed to the user.
// This shouldn't be exposed to the user.
var handleCompile;
var handleCompile;
 
// Dead code on eject: start
var isSmokeTest = process.argv.some(arg => arg.indexOf('--smoke-test') > -1);
var isSmokeTest = process.argv.some(arg => arg.indexOf('--smoke-test') > -1);
if (isSmokeTest) {
if (isSmokeTest) {
handleCompile = function (err, stats) {
handleCompile = function (err, stats) {
@@ -30,6 +31,7 @@ if (isSmokeTest) {
@@ -30,6 +31,7 @@ if (isSmokeTest) {
}
}
};
};
}
}
 
// Dead code on eject: end
var friendlySyntaxErrorLabel = 'Syntax error:';
var friendlySyntaxErrorLabel = 'Syntax error:';
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
1
CLA Signed
1
CLA Signed
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 participants
Reference: facebook/create-react-app!12457
Source branch: github/fork/Jiansen/clean-eject

Menu

Explore Projects Groups Snippets