Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

const enums are not inlined #400

Open
@axelo

Description

@axelo

Is this a bug report?

Yes.

const enums are not inlined when building (npm build / yarn build).

The reason can be understood here microsoft/TypeScript#11202

And the problem/feature is this line https://github.com/wmonk/create-react-app-typescript/blob/master/config/webpack.config.prod.js#L185

Our use case:
A large const enum that is generated and only a few values are actually used resulting in our bundle size to be a lot bigger than expected (+ 40kb). Plus we would like to think the values used to be just as strings while running and not accessed through an object.

Can you also reproduce the problem with npm 4.x?

Didn't seem relevant.

Which terms did you search for in User Guide?

const, enum, transpile

Environment

  1. npm ls react-scripts-ts (if you haven’t ejected):
    react-scripts-ts@2.17.0

  2. node -v:
    v8.11.1

  3. npm -v:
    5.6.0

  4. yarn --version (if you use Yarn):
    1.9.4

Then, specify:

  1. Operating system:
    macOS High Sierra

Steps to Reproduce

  1. yarn create react-app my-app --scripts-version=react-scripts-ts
  2. create an enum in the source directory
export const enum MyConstEnum {
  One = 'One',
  Two = 'Two'
}

Import the enum in app and only use 'One'.

import * as React from 'react';
import { MyConstEnum } from './MyConstEnum';

class App extends React.Component {
  public render() {
    return (
      MyConstEnum.One
    );
  }
}

export default App;
  1. yarn build
  2. Inspect build/static/js/main*.js seach for "One" and we find
    function(e){e.One="One",e.Two="Two"}(r||(r={}))}
    And
    t.prototype.render=function(){return i.a.One}
    instead of the inlined version

Expected Behavior

If we manually changes the transpile flag to false and run yarn build again and inspects main.js

t.prototype.render=function(){return"One"}

And we got the inlined version :)

Actual Behavior

We uses the non inlined version (as described in step 5)

Reproducible Demo

Steps to Reproduce should be enough, otherwise I can push a demo project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions