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
  • !7029
An error occurred while fetching the assigned milestone of the selected merge_request.

Interpolate variables into template before minification

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/cedrics/interpolate-template-before-minification into master 6 years ago
  • Overview 6
  • Commits 1
  • Pipelines 0
  • Changes 1

Created by: cedrics

Fixes https://github.com/facebook/create-react-app/issues/6448

We ran into a problem where a code snippet in our index.html was removed regardless of the NODE_ENV set:

 <script>
 if ("%NODE_ENV%" === "production") {
  // Production only configuration
}
 </script>

The problem was that the interpolation was only registered after the minification already ran. So from the minifier's point of view "%NODE_ENV%" === "production" is always false and the code block can therefore be eliminated.

I tested this out by using a local copy of react-scripts & react-dev-tools and rebuilding our project. I think the only potential bug this change could introduce would be if any steps between the template generation and the emit would actually themselves generate interpolated variables. Those would not be converted by the PR as it is. It may be possible to run the interpolation for both hooks if this turns out to be a problem.

Compare
  • master (base)

and
  • latest version
    2a1dd832
    1 commit, 2 years ago

1 file
+ 1
- 1

    Preferences

    File browser
    Compare changes
packages/react-dev-utils/InterpolateHtmlPlugin.js
+ 1
- 1
  • View file @ 2a1dd832


@@ -26,7 +26,7 @@ class InterpolateHtmlPlugin {
compiler.hooks.compilation.tap('InterpolateHtmlPlugin', compilation => {
this.htmlWebpackPlugin
.getHooks(compilation)
.beforeEmit.tap('InterpolateHtmlPlugin', data => {
.afterTemplateExecution.tap('InterpolateHtmlPlugin', data => {
// Run HTML through a series of user-specified string replacements.
Object.keys(this.replacements).forEach(key => {
const value = this.replacements[key];
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    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:
Source branch: github/fork/cedrics/interpolate-template-before-minification

Menu

Explore Projects Groups Snippets