简体   繁体   中英

How to prevent collapseWhitespace in create-react-app

I have run into issue related to How to avoid JSX component from condensing when React.js rendering it? . I would like to find a way how to avoid using {' '} . I have red somewhere that changing collapseWhitespace to false in webpack could resolve it. Is it achievable?

Inside JSX create-react-app will not collapse any white space, so

<p>Hello   World - Hello{'   '}World</p>

will result in:

<p>Hello   World - Hello   World</p>

However, the browser will usually collapse these white spaces into a single one. To prevent this set the 'white-space' css property like this:

<p style={{ whiteSpace: 'pre' }}>Hello   World - Hello{'   '}World</p>

The collapseWhitespace property exists for HTML minification as part of the html-webpack-plugin. This property is true for CRA and will minify the contents of public/index.html . In order to disable it you would have to eject .

See: cra-webpack-config

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM