Webpack

Multipage app / code spliting

[Tyler McGinnis] Code Splitting with React and React Router

const LazyHome = React.lazy(() => import('./Home'))
const LazyTopics = React.lazy(() => import('./Topics'))
<React.Suspense fallback={<Loading />}>
  <Route exact path='/' component={LazyHome} />
  <Route path='/settings' component={LazySettings} />
</React.Suspense>

[webpack.js.org] code-splitting

[React on AWS] code splitting in create react app

const AsyncHome = asyncComponent(() => import("./containers/Home"));
$ npm install --save react-loadable

Loaders

[webpack.js.org] concepts / loaders

writing-a-loader

A loader is a node module that exports a function. This function is called when a resource should be transformed by this loader.

Loaders can be chained. A chain is executed in reverse order.

input

a string containing the content of the resource file

output
  • JavaScript code as string or buffer
  • SourceMap as JavaScript object

Przykłady oficjalne

[github] webpack examples

Ecosystem

webpack-dev-server

[github] webpack-dev-server

All webpack CLI options are valid for the webpack-dev-server CLI too

[webpack.js.org] api/cli

html-webpack-plugin

[github] html-webpack-plugin

pug-loader

[github] pug-loader

sass-loader

[npm] sass-loader

babel-loader

[github] babel-loader