๐Ÿ“ฆ React ๊ฐ€์ ธ์˜จ ๊ตฌ์„ฑ ์š”์†Œ v6

24320 ๋‹จ์–ด reactcodesplittingwebdev

Long story short - nobody cares about version 1 and 2 - by that time the library, I am going to talk about, even had a different name. Version 3 never existed and the difference between 4 and 5 was a forwardRef, or React 16 support, which is a good reason for a breaking change. So, in short, v6 is actually 3rd iteration on the API.


๋ฒ„์ „ 6์œผ๋กœ ์—…๊ทธ๋ ˆ์ด๋“œํ•˜๋Š” ๊ฒƒ๋„ ์ƒˆ๋กœ์šด React ๊ธฐ๋Šฅ์— ์˜ํ•ด ๊ตฌ๋™๋ฉ๋‹ˆ๋‹ค.์ด๋ฒˆ์—๋Š” ๊ฐˆ๊ณ ๋ฆฌ๋ฅผ ํ†ตํ•ด React ๊ฐ€์ ธ์˜ค๊ธฐ ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ ๊ณต๊ฐœ ๊ฐˆ๊ณ ๋ฆฌ API๋ฅผ ๊ฐ€์ง„ ์ฒซ ๋ฒˆ์งธ ์ฝ”๋“œ ๋ถ„ํ•  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ Create React App๊ณผ ํ˜ธํ™˜๋˜๋Š” ์ฒซ ๋ฒˆ์งธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ babel ๋งคํฌ๋กœ์˜ ์ง€์› ๋•๋ถ„์ž…๋‹ˆ๋‹ค.

๊ทธ๋งŒ, ๊ทธ๋งŒ, ์™œ ๊ฒŒ์œผ๋ฅด์ง€ ์•Š์•„?


์„œ๋ฒ„ ์ธก ๋ Œ๋”๋ง, ์ถ”์  ๋ฐ ๊ณ ๊ธ‰ API๋‹ค์Œ์€ ๋น„๊ต ํ…Œ์ด๋ธ”์ž…๋‹ˆ๋‹ค.

์ค€๋น„ํ–ˆ์–ด๋›ฐ์–ด ๋“ค์–ด๊ฐ€!

ํ‹ฐ์นด์‹œ / react ๊ฐ€์ ธ์˜จ ๊ตฌ์„ฑ ์š”์†Œ


โœ‚๏ธ๐Ÿ“ฆ๋ฒˆ๋“ค ํ”„๋กœ๊ทธ๋žจ๊ณผ ๋ฌด๊ด€ํ•œ SSR ์นœ์„  ์ฝ”๋“œ ๋ถ„ํ•  ์†”๋ฃจ์…˜


๊ฐ€์ ธ์˜จ ๊ตฌ์„ฑ ์š”์†Œโœ‚


์ฝ”๋“œ ๋ฒ„์ŠคํŠธ๋Š” ํ•ญ์ƒ ์œ ํšจํ•ฉ๋‹ˆ๋‹ค*



๋ชจ๋“  ํ”Œ๋žซํผ๊ณผ ํ˜ธํ™˜๋˜๋Š” SSR ์นœ์ˆ™ํ•œ ์ฝ”๋“œ ๋ถ„ํ• 
ํ•œ ๋ฒˆ์˜ ๊ฐ€์ ธ์˜ค๊ธฐ์—์„œ ๋” ์ข‹์€ ๊ฒฝํ—˜์„ ์ œ๊ณตํ•˜๋‹ค





* It's really will never let you down. All credits to your bundler.


๐Ÿ‘‰ Usage | API | Setup | SSR | CCS Concurrent loading | Webpack/Parcel
๋„์„œ๊ด€
๊ฑฑ์ •ํ•˜๋‹ค
๊ณ ์ฒด ๊ณ„์ „๊ธฐ
์—ฐ๊ฒฐ
๋„์„œ๊ด€
๋น„๋ชจ๋“ˆ
๊ฐ€์ ธ์˜ค๊ธฐ(./${value})
๋ฐ”๋ฒจํ˜ผ
์›น ํŒจํ‚ค์ง€๋งŒ
๋ฐ˜์‘ํ•˜๋‹ค๊ฒŒ์œผ๋ฅด๋‹ค
โœ…
โŒ
โŒ
โŒ
โŒ
โŒ
๐Ÿ˜น
๋ฐ˜์‘ ๋กœ๋“œ ๊ฐ€๋Šฅ
โœ…
โœ…
โŒ
โŒ
โœ…
โŒ
โŒ
๐Ÿ˜ฟ
@ ๋กœ๋“œ ๊ฐ€๋Šฅ/๊ตฌ์„ฑ ์š”์†Œ
โœ…
โœ…
โŒ
โœ…
โŒ
โœ…
โŒ
๐Ÿ˜ฟ
๊ฐ€์ ธ์˜จ ๊ตฌ์„ฑ ์š”์†Œ
โœ…
โœ…
โœ…
โœ…
โœ…
โŒ
โœ…
๐Ÿ˜ธ

Read more about what this table displays


์ฃผ์š” ํŠน์ง•:

  • ์ผ.๏ธโƒฃ ๋‹จ์ผ ์ง„์ƒ ์ถœ์ฒ˜ - ๋‹น์‹ ์˜ ๋ฌถ์Œ๊ธฐ ๊ตฌ๋™ ๋ชจ๋“ 

  • ๐Ÿ“– ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ฝ”๋“œ ๋ถ„ํ• 
  • ๐Ÿง™๏ธ ํ˜ผํ•ฉ ๋ฐ ๋ Œ๋”๋ง ์‚ฌ์ „ ํ˜ธํ™˜

  • ๐Ÿ’ก TypeScript ๋ฐ”์ธ๋”ฉ

  • โš›๏ธ ๋ฐ˜์‘ํ•˜๋‹คLazy Underground(ํ•ซ ๋ชจ๋“ˆ ์—…๋ฐ์ดํŠธ๊ฐ€ ๋น„ํ™œ์„ฑํ™”๋œ ๊ฒฝ์šฐ)

  • ๐ŸŒŸ ํด๋ผ์ด์–ธํŠธ ๋น„๋™๊ธฐํ™”, ์„œ๋ฒ„ ๋™๊ธฐํ™”.์„œ์ŠคํŽœ์Šค ์ง€์›(
  • )
    View on GitHub

    ๊ฐ€์ ธ์˜จ ์—ฐ๊ฒฐ ์‚ฌ์šฉ


    ์ง€์—ฐ ์ ์žฌ๋Š” React.lazy๊ณผ Components์— ๊ด€ํ•œ ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ์–ด๋– ํ•œ ๋ณ€์ฒด ๋’ค์—๋„ ๋™์  import๋งŒ ์žˆ์„ ๋ฟ, ์ ˆ๋Œ€ ๋ชจ๋“  ๊ฒƒ์„ ์ ์žฌํ•  ์ˆ˜ ์žˆ๋‹ค.๋งˆ์šดํŠธ ์ƒํƒœ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ๊ฒƒ์€ ์ ๋‹นํ•œ ๋ฐ˜์‘ ์ง‘์ ์ผ ๋ฟ์ž…๋‹ˆ๋‹ค.
    // a STATIC table with imports
    const languages = {
      'en': () => import('./i18n/en'), // it's probably a json...
      'de': () => import('./i18n/de'),
    }
    // just a helper function
    const pickLanguage = (lng) => languages[lng];
    // your component
    const MyI18nProvider = ({lng, children}) => {
      // let's pick and provide correct import function for our language
      const {
       imported: messages = {} // defaulting to empty object
      } = useImported(pickLanguage(lng));
    
      // set messages to the Provider
      return <I18nProvider value={messages}>{children}</I18nProvider>
    }
    
    ๊ทธ๊ฒŒ ๋‹ค์•ผ.์œ ์ผํ•œ ๋ฌธ์ œ๋Š” ๊ธฐ๋ณธ {}์ด ๋ชจ๋“  ๋ Œ๋”๋ง์—์„œ ์œ ์ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด ๊ตฌ์„ฑ ์š”์†Œ ์ด์™ธ์˜ ๋‹จ๋… ๋ณ€์ˆ˜๋กœ ์ถ”์ถœํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ์ข‹๋‹ค.ํ•˜์ง€๋งŒ ์ด๊ฒƒ์€ ๋„ค๊ฐ€ ๊ฑฑ์ •ํ•ด์•ผ ํ•  ์ผ์ด ์•„๋‹ˆ๋‹ค.useImported์€ ์›ํ•˜๋Š” ๋‚ด์šฉ์„ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ์œผ๋ฉฐ, react-imported-component์ด ๊ณต๊ฐœํ•œ ๋‹ค๋ฅธ ๋ชจ๋“  API๋Š” ๊ทธ ์œ„์— ์„ธ์›Œ์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.

    importedModule ๋ฐ importedModule

    useImported์€ ํ•ญ์ƒ ๊ฝ‰ ์ฐฌ ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๋•Œ๋กœ๋Š” ๋”์šฑ ์„ฑ๋ช…์ ์ธ ๋‚ด์šฉ์„ ์„ ํƒํ•  ์ˆ˜ ์žˆ๋‹ค.
    ๋”ฐ๋ผ์„œreactrenderprops ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด ์›ํ•˜๋Š” ๋‚ด์šฉ์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋Š” ์กฐ์ˆ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.๋Œ€๋ถ€๋ถ„์˜ ์‚ฌ๋žŒ๋“ค์—๊ฒŒ ์ด๋Ÿฐ ๋ชจ๋ธ์€ loadable.lib์œผ๋กœ ๋” ๋„๋ฆฌ ์•Œ๋ ค์ ธ ์žˆ๋‹ค.
    import {importedModule, ImportedModule} from 'react-imported-component';
    
    // you can use it to codesplit and  use `momentjs`, no offence :)
    const Moment = importedModule(() => import('moment'));
    
    <Moment fallback="long time ago">
      {(momentjs /* default imports are auto-imported*/) => momentjs(date).fromNow()}
    </Moment>
    
    // or, again, translations
    
    <ImportedModule
     import={() => import('./i18n/en')}
     // fallback="..." // will throw to the Suspense boundary without fallback provided
    >
     {(messages) => <I18nProvider value={messages}>{children}</I18nProvider> }
    </ImportedModule>
    

    ๊ฐ€์ ธ์˜ค๊ธฐ์™€ ๊ฒŒ์œผ๋ฆ„


    ๋˜ํ•œ ๊ณตํ†ต API-imported ๋ฐ lazy ๋‘ ๊ฐœ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
    ๊ทธ ์ค‘์—์„œ lazy์€ React.lazy์ฒ˜๋Ÿผ ํ‰๋ฒ”ํ•œ ์˜์‚ฌ๋กœ ์ƒ์‚ฐ ์ค‘์— ๊ฒŒ์œผ๋ฅด๋‹ค. imported์€ 1์„ธ๋Œ€ ์ฝ”๋“œ ๋ถ„ํ•  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ํ˜ธํ™˜๋˜๋Š” API๋กœ ๊ฐ€์ ธ์˜จ ๋‚ก์€ ์ œํ’ˆ์ด๋‹ค.
    const Component = importedComponent( () => import('./Component'), {
      LoadingComponent: Spinner, // what to display during the loading
      ErrorComponent: FatalError // what to display in case of error
    });
    
    Component.preload(); // force preload
    
    // render it
    <Component... />
    

    ๋ณ„๊ฒƒ


    React ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ ์ง€์› ๋งŒ๋“ค๊ธฐ


    CRA์™€ ๊ด€๋ จํ•˜์—ฌ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์„ธ ๊ฐ€์ง€ ์‚ฌํ•ญ์„ ์•Œ์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ์€ ํ”„๋กœ์ ํŠธ์˜ ์„ค์ •์„ ๋ณ€๊ฒฝํ•˜๊ธฐ ์–ด๋ ต์Šต๋‹ˆ๋‹ค.
  • ์„ ์ด๋ ‡๊ฒŒ ํ•˜์ง€ ๋งˆ์‹ญ์‹œ์˜ค.
  • SSR ๋˜๋Š” ์‚ฌ์ „ ๋ Œ๋”๋ง
  • ์ง€์›
  • ๋” ์ข‹์€ ์ฝ”๋“œ ๋ถ„ํ• ์ด ์ข€ ๋ณต์žกํ•ฉ๋‹ˆ๋‹ค.
  • ๊ทธ๋Ÿฌ๋‚˜ ๋‹ค๋ฅธ SSR์˜ ์šฐํ˜ธ์ ์ธ ์ฝ”๋“œ ๋ถ„ํ•  ์†”๋ฃจ์…˜์€babel๊ณผ ์›นํŒฉ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์‚ฌ์šฉํ•ด์•ผ ์ž‘๋™ํ•˜์ง€๋งŒ react-imported-component์€ ์›นํŒฉ์˜ ์–ด๋–ค ๊ฒƒ๋„ ํ•„์š”ํ•˜์ง€ ์•Š๊ณ  ๋ฌถ์Œ ํ”„๋กœ๊ทธ๋žจ์— ๋…๋ฆฝ์ ์ด๋ฉฐ ์›นํŒฉ ๋งคํฌ๋กœ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ CRA์˜ ์œ ์ผํ•œ ๊ธฐ์กด ๋„๊ตฌ์ž…๋‹ˆ๋‹ค.react-imported-component/macro๋งŒ ์‚ฌ์šฉํ•˜๋ฉด ์˜ค๋Š˜ ์—ฌ๊ธฐ๊นŒ์ง€
    import {imported} from "react-imported-component/macro";
    imported(()=>import('./aGoodDay'));
    

    ๋ฒˆ๋“ค ๋…๋ฆฝ์„ฑ


    ์ด๊ฒƒ์€ ์„ธ ๊ฐ€์ง€ ๋‹ค๋ฅธ ์ผ์„ ์˜๋ฏธํ•œ๋‹ค.
  • ์€ ํŒจํ‚ค์ง€ ๋ฌถ์Œ๊ธฐ์™€ ํ˜ธํ™˜๋˜๊ฑฐ๋‚˜,rollup,์‹œ์Šคํ…œjs์ž…๋‹ˆ๋‹ค.๋„ค๊ฐ€ ์–ด๋–ค ๋ฌถ์Œ์„ ์‚ฌ์šฉํ•˜๋“ ์ง€ ๊ฐ„์— ๊ทธ๊ฒƒ์€ ์ผํ•  ๊ฒƒ์ด๋‹ค.
  • ํ˜ธํ™˜ react-snap.'์‚ฌ์šฉ ์ƒํ™ฉ ์ถ”์ '์€ ์˜์›ํžˆ ๋ฉˆ์ถ”์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ—ค๋” ์—†๋Š” ๋ธŒ๋ผ์šฐ์ €์—์„œ ํŽ˜์ด์ง€๋ฅผ ๋ณด์—ฌ์ฃผ๋ฉด'๋‹ค์‹œ ์–ด๋–ค ๋ธ”๋ก์„ ๋ณด์—ฌ์•ผ ํ•˜๋Š”๊ฐ€'๋ผ๊ณ  ๋ฌผ์–ด๋ณด๊ณ  ๋ชฉ๋ก์„ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.๋˜ํ•œ ๊ด€๋ฆฌ๋˜์ง€ ์•Š๋Š” "real"imports์—๋„ ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.์ด๊ฒƒ์€ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ค‘์š”ํ•˜์ง€ ์•Š๋‹ค.
  • ์€ ๋”์šฑ ๊นŠ์ด ์žˆ๊ฒŒ ํ†ตํ•ฉ๋œ ์ฝ”๋“œ ๋ถ„ํ•  ์†”๋ฃจ์…˜๋ณด๋‹ค ํšจ๊ณผ๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์— SSR ๊ธฐ๊ฐ„์— ์‚ฌ์šฉ๋œ ๋ธ”๋ก์„ ์ƒˆ๋กœ ๊ณ ์น  ์ˆ˜ ์žˆ๋‹ค.๋‚ด๊ฐ€ ๋งํ•œ ๋ฐ”์™€ ๊ฐ™์ด ํ™•์‹คํžˆ ๊ทธ๋ ‡๋‹ค.
  • ๋น„์ฆˆ๋‹ˆ์Šค ํ”„๋กœ์„ธ์Šค ๋กœ๋“œ ์ค‘


    ์Šคํฌ๋ฆฝํŠธ์˜ ์žฌ์ˆ˜ํ™”๋ฅผ ์‹คํ˜„ํ•˜๋Š” ์ฒซ ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์€ ์ ์žฌ ๊ณผ์ •์˜ ํšจ์œจ์„ ๋†’์ด๋Š” ๊ฒƒ์ด๋‹ค.imported-component์€ ๋‹จ๋… ์ž…๊ตฌ์ ์ธ /boot์„ ์ œ๊ณตํ•˜์—ฌ ๋ฉ”์ธ ์Šคํฌ๋ฆฝํŠธ ํ‰๊ฐ€ ์ „์— ์ดˆ๊ธฐํ™” ๊ณผ์ •์„ ์‹œ์ž‘ํ•˜์—ฌ ์ง€์—ฐ๋œ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋ฏธ๋ฆฌ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.์ด๊ฒƒ์€ ๋งค์šฐ ์ข‹์€ CRA ๋˜๋Š” Parcel ์†”๋ฃจ์…˜์ž…๋‹ˆ๋‹ค. HTML์— ์‚ฝ์ž…ํ•  ๋ธ”๋ก ํŒŒ์ผ (์ถ”๊ฐ€ ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ์„ค์น˜๋˜์–ด ์žˆ์ง€ ์•Š์Œ) ์˜ ์‹ค์ œ ์ด๋ฆ„์„ ๋ชจ๋ฅผ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
    import "../async-requires";
    import {injectLoadableTracker} from "react-imported-component/boot";
    // ^ just 1kb
    
    // injects runtime
    injectLoadableTracker('importedMarks');
    
    
    // give browser a tick to kick off script loading
    Promise.resolve().then(() =>
      Promise.resolve().then(() => { 
        // the rest of your application
        // imported with a little "pause"
        require('./main')
      })
    );
    
    ์ด๊ฒƒ์€ ๋งค์šฐ ๊ฐ„๋‹จํ•˜๊ณ  ์žฌ๋ฏธ์žˆ๋‹ค. ๋‹น์‹ ์˜ js๋Š” ํ•ด์„๋˜๊ณ  ํ‰๊ฐ€๋˜์—ˆ์ง€๋งŒ ์™„์ „ํžˆ ์‹คํ–‰๋˜์ง€ ์•Š์•˜๋‹ค.๊ทธ๋ฆฌ๊ณ  imported์€ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐ ํ•„์š”ํ•œ ๋ธ”๋ก์„ ํ„ฐ์น˜ํ•ฉ๋‹ˆ๋‹ค. ๋ถˆ๋Ÿฌ์˜ค๋Š” imports๋งŒ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.๊ทธ๋Ÿฐ ๋‹ค์Œ ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์ด ๊ณ„์† ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.
    ์ด ์•„์ด๋””์–ด๋ฅผ ์„ค๋ช…ํ•˜๊ธฐ ์œ„ํ•ด ๋ผ์ดํŠธํ•˜์šฐ์Šค ์Šค๋ƒ…์ƒท ๋‘ ๊ฐœ(4x ๊ฐ์†, 3Mb JS ๋ฒˆ๋“ค)๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
  • ์€ ์•ฝ์†์—์„œ main์„ ์š”๊ตฌํ•ฉ๋‹ˆ๋‹ค. ์ƒ๊ธฐ์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • ์€ ์•ฝ์†์—์„œ main์ด ํ•„์š”ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ƒ๊ธฐ์™€ ๊ฐ™์ด (catch์œผ๋กœ ์ด๋™ํ•  ๋ฟ, ๋ชจ๋“  ์ฝ”๋“œ๋Š” ์—ฌ์ „ํžˆ ๋ฌถ์—ฌ ์žˆ์Šต๋‹ˆ๋‹ค)

  • ์•„๋‹ˆ๋ฉด ์œค๊ณฝํ™”์—ผ๋„๋ฅผ ๋” ๋ฏฟ์œผ์‹œ๊ฒ ์–ด์š”?

    ์™ผ์ชฝ์˜ ์ž‘์€'ํƒ€์ž„๋ฐ•์Šค'์™€ ๋ธŒ๋ผ์šฐ์ €์— ๋Œ€ํ•œ ๋งˆ์ดํฌ๋กœ ์ž‘์—…์„ ์ฃผ์˜ํ•˜์—ฌ ์˜ค๋ฅธ์ชฝ์˜ ๋„คํŠธ์›Œํฌ ๋‚ด์šฉ์„ ์‹œ์ž‘ํ•˜์‹ญ์‹œ์˜ค.

    ์ด ํƒ€์ž„๋ฐ•์Šค๊ฐ€ ์–ผ๋งˆ๋‚˜ ์ž‘์€์ง€ ์ฃผ์˜ํ•˜์„ธ์š”.
    ์Šคํฌ๋ฆฝํŠธ ํ”„๋ฆฌ๋กœ๋“œ์™€ ํ”„๋ฆฌํŽ˜์น˜ ๊ฐ™์€ ๋ชจ๋“  ์ผ์€ ์ค‘์š”ํ•˜์ง€ ์•Š๋‹ค. - ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์—†์–ด๋„ ๊ทธ๋ ‡๊ฒŒ ๋‚˜์˜์ง€ ์•Š๋‹ค.๊ทธ๋ž˜์„œ 2์ฐจ ๋ฐ˜์‘๊ณผ CRA์˜ ์ƒ์ž๋ฅผ ์—ด๋ฉด ๋ฐ”๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์„ ๊ฑฐ์˜ˆ์š”.

    ๊นŠ์ด ์žˆ๋Š” ํŒจํ‚ค์ง€ ํ†ตํ•ฉ


    ๊ทธ๋Ÿฌ๋‚˜ ๊ฐ€์žฅ ์ข‹์€ ๊ฒฐ๊ณผ๋Š” ๋”์šฑ ์„ธ๋ฆฝ์ ์ธ ๋ฐฉ๋ฒ•์ด ํ•„์š”ํ•˜๋‹ค.v6์˜ ๋˜ ๋‹ค๋ฅธ ๋ณ€ํ™”์ธ ๋‹จ๋… ์›น ํ†ตํ•ฉ ํŒจํ‚ค์ง€๊ฐ€ ๋„์›€์ด ๋  ๊ฒƒ์ด๋‹ค.์ด๋ฆ„์ด ๋šœ๋ ทํ•˜๋‹ค.

    ํ‹ฐ์นด์‹œ / ํŒจํ‚ค์ง€ ๊ฐ€์ ธ์˜ค๊ธฐ


    ๐Ÿ“ํ†ต๊ณ„ ํŒจํ‚ค์ง€ ํ”Œ๋Ÿฌ๊ทธ์ธ ๋ฐ๐Ÿ’ฉ์›นํŒฉflushchunks๊ฐ€ ์•„์ด๋ฅผ ๋‚ณ์•˜์–ด์š”!


    ํŒจํ‚ค์ง€ ๊ฐ€์ ธ์˜ค๊ธฐ


    ์šฐ๋ฆฌ๋Š” ์ •ํ™•ํ•œ ๋ฐฉ์‹์œผ๋กœ ๋„ˆ์˜ ์—‰๋ฉ์ด๋ฅผ ์ˆ˜์ž…ํ•  ๊ฒƒ์ด๋‹ค.

    ๐Ÿ“ stats-webpack-plugin and ๐Ÿ’ฉwebpack-flush-chunks had a baby!


    ์„œ๋ฒ„ ์ธก API


    ํŒจํ‚ค์ง€ ํ”Œ๋Ÿฌ๊ทธ์ธ

    const {ImportedPlugin} = require('webpack-imported')
    module.exports = {
      plugins: [
        new ImportedPlugin('imported.json')
      ]
    };

    This will output imported.json as a one of the emitted assets, with all the information carefully sorted.

    Stat.json

    If you have only stat.json generated somehow you can convert into into "imported" format

    import {importStats} from "webpack-imported"
    import stats from 'build/stats.json'
    const importedStat = importStats(stats);

    SSR API

    • importedAssets(stats, chunks, [tracker]) - return all assets associated with provided chunks. Could be provided a tracker to prevent duplications between runs.
    • createImportedTracker() - creates a duplication prevention tracker
    import {importedAssets} from "webpack-imported"
    import importedStat from "build/imported.json"; 
    โ€ฆ

    A webpack plugin to gather the data, and clientside API, including React binding, to handle everything out of the box.

    import importedData from 'build/imported.json';
    
    <WebpackImport
       stats={importedData}
       chunks={getMarkedChunks(marks)}
       publicPath={importedData.config.publicPath}
       crossOrigin={CDN_ANONYMOUS}
    />
    

    CSS


    CSS๋„ ๊ฐ€์žฅ ์ข‹์€ ๋ฐฉ์‹์œผ๋กœ ์ฒ˜๋ฆฌ๋œ๋‹ค. ์ผ๋ฐ˜์ ์ธ CSS ํŒŒ์ผ์— ์žˆ์–ด์„œ ๊ด€๊ฑด์ ์ธ ์Šคํƒ€์ผ ์ถ”์ถœ์€ ์ƒ์ž๋ฅผ ์—ด๋ฉด ๋ฐ”๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

    ํ‹ฐ์นด์‹œ / ์‚ฌ์šฉ ์Šคํƒ€์ผ


    ๐Ÿ“ํŽ˜์ด์ง€๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” ๋ชจ๋“  ๊ด€๊ฑด์ ์ธ ์Šคํƒ€์ผ์ž…๋‹ˆ๋‹ค.


    ์‚ฌ์šฉ ์Šคํƒ€์ผ


    ๋ Œ๋”๋ง ํŽ˜์ด์ง€์— ์‚ฌ์šฉํ•  ๋ชจ๋“  ์Šคํƒ€์ผ ๊ฐ€์ ธ์˜ค๊ธฐ


    Bundler and framework independent CSS part of SSR-friendly code splitting


    ์ฃผ์–ด์ง„ HTML ๋ฐ/๋˜๋Š” ์ธ๋ผ์ธ ํ‚ค ์Šคํƒ€์ผ์—์„œ ์‚ฌ์šฉ๋œ css๊ฐœ์˜ ํŒŒ์ผ ๊ฐ์ง€
    ๋™๊ธฐํ™” ๋˜๋Š” ํ๋ฆ„ ๋ Œ๋”๋ง์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

    ์ฝ”๋“œ ๋ถ„ํ• 


    ์ด๊ฒƒ์€ React๊ฐ€ ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ๋ฌด๊ด€ํ•˜๋”๋ผ๋„ ์ฝ”๋“œ ๋ถ„ํ• , ์„œ๋ฒ„ ์ชฝ ๋ Œ๋”๋ง, React์— ๊ด€ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.
    ์ฝ”๋“œ ๋ถ„ํ• ์€ ์ข‹์€ ํŠน์„ฑ์ด๊ณ  SSR๋„ ์ข‹์ง€๋งŒ ๋‹น์‹ ์€
    ํŽ˜์ด์ง€๋ฅผ ํ™œ์„ฑํ™”ํ•˜๊ธฐ ์ „์— ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“  scripts์„ ํด๋ผ์ด์–ธํŠธ์— ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.
    ๋ชจ๋‘๊ฐ€ ์ด์•ผ๊ธฐํ•˜๊ณ  ์žˆ๋Š” ๊ฒƒ์€ .css์ด ์•„๋‹ˆ๋ผ .js์ด๋‹ค.
    ์ด๊ฒƒ์€ ๋‹ค๋ฅธ ๋ฐฉ์‹์œผ๋กœ ์™„์„ฑ๋œ ๊ฒƒ์ด๋‹ค.์ด๊ฒƒ์€ ํฐ ์ž„๋ฌด๊ฐ€ ์•„๋‹ˆ๋‹ค. ์ฝ”๋“œ๋กœ ๋ธ”๋ก์„ ๋ถ„ํ• ํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด
    ์ถ”์ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. - ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์œผ๋ฉฐ ๊ตฌ์„ฑ ์š”์†Œ๊ฐ€ ๋‚ด๋ถ€์ ์œผ๋กœ ์ •์˜๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
    CSS๊ฐ€ ๋” ์–ด๋ ค์›Œ์š”. - ๋žœ๋ค ํด๋ž˜์Šค๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”. ๋‹ค์Œ์€์š”?๋„ˆ๋Š”...
    View on GitHub

    ํ๋ฅด๋‹ค


    ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—๋Š” Streamig ์นœํ™”์ ์ธ API๊ฐ€ ์žˆ์œผ๋ฉฐ ์›ํ•˜๋Š” ์ตœ์ƒ์˜ TTFB๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

    ์™œ, ์™œ?


    ์ฝ”๋“œ ๋ถ„ํ• , ์ฝ”๋“œ ๋ถ„ํ• , ์ฝ”๋“œ ๋ถ„ํ• , JS๋‚˜ CSS ๋‚ฉํ’ˆ์„ ์ตœ์ ํ™”ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ๊ณ  ์‹ถ๋‹ค๋ฉด.


    ๊ฒฐ๋ก 

  • ์—ฐ๊ฒฐ API
  • ๋กœ๋“œ ๋ชจ๋“ˆ
  • ์–ด์…ˆ๋ธ”๋ฆฌ ๋กœ๋“œโ€‹
  • , ์„œ๋ฒ„ ์ธก ์ถ”์ 
  • ํฌํ•จ
  • babel ๋งคํฌ๋กœ ์ง€์›
  • ์€ ์›นํŒฉ์— ์—ฐ๊ฒฐ๋˜์ง€ ์•Š์•˜์ง€๋งŒ ๋”์šฑ ๊นŠ์€ ๋ธŒ๋ผ์šฐ์ € ํ†ตํ•ฉ
  • ์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค
  • ๋‹น์‹ ์„ ์œ„ํ•ด ์ œ์ž‘!
  • ๐Ÿ‘‰ https://github.com/theKashey/react-imported-component

    ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ