const enums are not inlined #400
Description
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
-
npm ls react-scripts-ts
(if you haven’t ejected):
react-scripts-ts@2.17.0 -
node -v
:
v8.11.1 -
npm -v
:
5.6.0 -
yarn --version
(if you use Yarn):
1.9.4
Then, specify:
- Operating system:
macOS High Sierra
Steps to Reproduce
- yarn create react-app my-app --scripts-version=react-scripts-ts
- 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;
- yarn build
- 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.