Split React into separate chunk to reduce bundle sizes

This commit is contained in:
hensm
2018-12-07 20:51:24 +00:00
parent fec2e0808b
commit 7e26e8d47d
3 changed files with 24 additions and 11 deletions

View File

@@ -3,6 +3,7 @@
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="index.css">
<script src="../vendor.js" defer></script>
<script src="bundle.js" defer></script>
</head>
<body>

View File

@@ -1,11 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="styles/index.css">
<script src="bundle.js" defer></script>
</head>
<body>
<div id="root"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="styles/index.css">
<script src="../vendor.js" defer></script>
<script src="bundle.js" defer></script>
</head>
<body>
<div id="root"></div>
</body>
</html>

View File

@@ -23,6 +23,17 @@ module.exports = (env) => ({
filename: "[name].js"
, path: `${env.outputPath}`
}
, optimization: {
splitChunks: {
cacheGroups: {
vendor: {
name: "vendor"
, test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/
, chunks: "all"
}
}
}
}
, plugins: [
new webpack.DefinePlugin({
"EXTENSION_NAME" : JSON.stringify(env.extensionName)