This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| module.exports = { | |
| ... | |
| optimization: { | |
| splitChunks: { | |
| chunks: 'all', | |
| cacheGroups: { | |
| defaultVendors: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import _ from "lodash"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import join from "lodash/join"; | |
| function HelloComponent() { | |
| const element = document.createElement("div"); | |
| element.innerText = join( | |
| ["Hello from bundle size demo", "with lodash join"], | |
| " " | |
| ); | |
| return element; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function HelloComponent() { | |
| const button = document.createElement('button'); | |
| button.innerText = 'Hello'; | |
| button.onclick = () => { | |
| return import( | |
| /* webpackChunkName: "lodash" */ | |
| 'lodash/join' | |
| ).then(({ default: join }) => { | |
| const greeting = join( | |
| ['Hello from bundle size demo', 'with lodash loaded dynamically'], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { join } from "lodash"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| plugins: [ | |
| new webpack.IgnorePlugin({ | |
| resourceRegExp: /^\.\/locale$/, | |
| contextRegExp: /moment$/, | |
| }), | |
| new BundleAnalyzerPlugin({ openAnalyzer: false }), | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script src="vendors.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import moment from 'moment'; | |
| function HelloComponent() { | |
| const element = document.createElement('div'); | |
| element.innerText = `Now ${moment().format('L LT')}`; | |
| return element; | |
| } | |
| document.body.appendChild(HelloComponent()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState } from 'react'; | |
| import Login from './Login'; | |
| export default function App({ user }) { | |
| // user not logged in, show login form | |
| if (!user) return <Login />; | |
| return ( | |
| <div> | |
| Hello, {user.username}. <a href="/logout">Logout</a> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export async function login(username, password) { | |
| const res = await fetch('/login', { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ username, password }), | |
| }); | |
| if (res.status === 401) return {}; | |
| const user = await res.json(); |