Unverified Commit 1fe1f7fc authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Implement autodllplugin (#4951)

* Implement autodllplugin

* Add flow-typed for autodll-webpack-plugin
parent fcf9625e
...@@ -18,6 +18,7 @@ import BuildManifestPlugin from './webpack/plugins/build-manifest-plugin' ...@@ -18,6 +18,7 @@ import BuildManifestPlugin from './webpack/plugins/build-manifest-plugin'
import ChunkNamesPlugin from './webpack/plugins/chunk-names-plugin' import ChunkNamesPlugin from './webpack/plugins/chunk-names-plugin'
import { ReactLoadablePlugin } from './webpack/plugins/react-loadable-plugin' import { ReactLoadablePlugin } from './webpack/plugins/react-loadable-plugin'
import {SERVER_DIRECTORY, NEXT_PROJECT_ROOT, NEXT_PROJECT_ROOT_NODE_MODULES, NEXT_PROJECT_ROOT_DIST, DEFAULT_PAGES_DIR, REACT_LOADABLE_MANIFEST, CLIENT_STATIC_FILES_RUNTIME_WEBPACK, CLIENT_STATIC_FILES_RUNTIME_MAIN} from '../lib/constants' import {SERVER_DIRECTORY, NEXT_PROJECT_ROOT, NEXT_PROJECT_ROOT_NODE_MODULES, NEXT_PROJECT_ROOT_DIST, DEFAULT_PAGES_DIR, REACT_LOADABLE_MANIFEST, CLIENT_STATIC_FILES_RUNTIME_WEBPACK, CLIENT_STATIC_FILES_RUNTIME_MAIN} from '../lib/constants'
import AutoDllPlugin from 'autodll-webpack-plugin'
// The externals config makes sure that // The externals config makes sure that
// on the server side when modules are // on the server side when modules are
...@@ -135,6 +136,18 @@ export default async function getBaseWebpackConfig (dir: string, {dev = false, i ...@@ -135,6 +136,18 @@ export default async function getBaseWebpackConfig (dir: string, {dev = false, i
].filter(Boolean) ].filter(Boolean)
} : {} } : {}
const resolveConfig = {
extensions: ['.js', '.jsx', '.json'],
modules: [
NEXT_PROJECT_ROOT_NODE_MODULES,
'node_modules',
...nodePathList // Support for NODE_PATH environment variable
],
alias: {
next: NEXT_PROJECT_ROOT
}
}
let webpackConfig = { let webpackConfig = {
mode: dev ? 'development' : 'production', mode: dev ? 'development' : 'production',
devtool: dev ? 'cheap-module-source-map' : false, devtool: dev ? 'cheap-module-source-map' : false,
...@@ -170,17 +183,7 @@ export default async function getBaseWebpackConfig (dir: string, {dev = false, i ...@@ -170,17 +183,7 @@ export default async function getBaseWebpackConfig (dir: string, {dev = false, i
strictModuleExceptionHandling: true strictModuleExceptionHandling: true
}, },
performance: { hints: false }, performance: { hints: false },
resolve: { resolve: resolveConfig,
extensions: ['.js', '.jsx', '.json'],
modules: [
NEXT_PROJECT_ROOT_NODE_MODULES,
'node_modules',
...nodePathList // Support for NODE_PATH environment variable
],
alias: {
next: NEXT_PROJECT_ROOT
}
},
resolveLoader: { resolveLoader: {
modules: [ modules: [
NEXT_PROJECT_ROOT_NODE_MODULES, NEXT_PROJECT_ROOT_NODE_MODULES,
...@@ -205,6 +208,21 @@ export default async function getBaseWebpackConfig (dir: string, {dev = false, i ...@@ -205,6 +208,21 @@ export default async function getBaseWebpackConfig (dir: string, {dev = false, i
].filter(Boolean) ].filter(Boolean)
}, },
plugins: [ plugins: [
// Precompile react / react-dom for development, speeding up webpack
dev && !isServer && new AutoDllPlugin({
filename: '[name]_[hash].js',
path: './static/dll',
context: dir,
entry: {
dll: [
'react',
'react-dom'
]
},
config: {
resolve: resolveConfig
}
}),
// This plugin makes sure `output.filename` is used for entry chunks // This plugin makes sure `output.filename` is used for entry chunks
new ChunkNamesPlugin(), new ChunkNamesPlugin(),
!isServer && new ReactLoadablePlugin({ !isServer && new ReactLoadablePlugin({
......
...@@ -13,6 +13,12 @@ export default class BuildManifestPlugin { ...@@ -13,6 +13,12 @@ export default class BuildManifestPlugin {
const mainJsChunk = chunks.find((c) => c.name === CLIENT_STATIC_FILES_RUNTIME_MAIN) const mainJsChunk = chunks.find((c) => c.name === CLIENT_STATIC_FILES_RUNTIME_MAIN)
const mainJsFiles = mainJsChunk && mainJsChunk.files.length > 0 ? mainJsChunk.files.filter((file) => /\.js$/.test(file)) : [] const mainJsFiles = mainJsChunk && mainJsChunk.files.length > 0 ? mainJsChunk.files.filter((file) => /\.js$/.test(file)) : []
for (const filePath of Object.keys(compilation.assets)) {
if (/^static\/dll\//.test(filePath)) {
mainJsFiles.push(filePath)
}
}
// compilation.entrypoints is a Map object, so iterating over it 0 is the key and 1 is the value // compilation.entrypoints is a Map object, so iterating over it 0 is the key and 1 is the value
for (const [, entrypoint] of compilation.entrypoints.entries()) { for (const [, entrypoint] of compilation.entrypoints.entries()) {
const result = ROUTE_NAME_REGEX.exec(entrypoint.name) const result = ROUTE_NAME_REGEX.exec(entrypoint.name)
...@@ -27,9 +33,8 @@ export default class BuildManifestPlugin { ...@@ -27,9 +33,8 @@ export default class BuildManifestPlugin {
} }
const filesForEntry = [] const filesForEntry = []
for (const chunk of entrypoint.chunks) { for (const chunk of entrypoint.chunks) {
// If there's no name // If there's no name or no files
if (!chunk.name || !chunk.files) { if (!chunk.name || !chunk.files) {
continue continue
} }
......
// flow-typed signature: 6efcfad8e6dad5d1ef55854d4f6d2272
// flow-typed version: <<STUB>>/autodll-webpack-plugin_v0.4.2/flow_v0.73.0
/**
* This is an autogenerated libdef stub for:
*
* 'autodll-webpack-plugin'
*
* Fill this stub out by replacing all the `any` types.
*
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* https://github.com/flowtype/flow-typed
*/
declare module 'autodll-webpack-plugin' {
declare module.exports: any;
}
/**
* We include stubs for each file inside this npm package in case you need to
* require those files directly. Feel free to delete any files that aren't
* needed.
*/
declare module 'autodll-webpack-plugin/lib/createCompileIfNeeded' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/createConfig' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/createHandleStats' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/createHash' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/createLogger' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/createMemory' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/createSettings' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/getEnv' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/getInstanceIndex' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/index' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/mapParentConfig' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/normalizeEntry' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/paths' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/plugin' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/utils/fs' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/utils/index' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/utils/safeClone' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/lib/validateCache' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/createCompileIfNeeded' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/createConfig' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/createHandleStats' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/createHash' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/createLogger' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/createMemory' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/createSettings' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/getEnv' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/getInstanceIndex' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/index' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/mapParentConfig' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/normalizeEntry' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/paths' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/plugin' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/utils/fs' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/utils/index' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/utils/safeClone' {
declare module.exports: any;
}
declare module 'autodll-webpack-plugin/src/validateCache' {
declare module.exports: any;
}
// Filename aliases
declare module 'autodll-webpack-plugin/lib/createCompileIfNeeded.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/createCompileIfNeeded'>;
}
declare module 'autodll-webpack-plugin/lib/createConfig.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/createConfig'>;
}
declare module 'autodll-webpack-plugin/lib/createHandleStats.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/createHandleStats'>;
}
declare module 'autodll-webpack-plugin/lib/createHash.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/createHash'>;
}
declare module 'autodll-webpack-plugin/lib/createLogger.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/createLogger'>;
}
declare module 'autodll-webpack-plugin/lib/createMemory.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/createMemory'>;
}
declare module 'autodll-webpack-plugin/lib/createSettings.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/createSettings'>;
}
declare module 'autodll-webpack-plugin/lib/getEnv.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/getEnv'>;
}
declare module 'autodll-webpack-plugin/lib/getInstanceIndex.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/getInstanceIndex'>;
}
declare module 'autodll-webpack-plugin/lib/index.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/index'>;
}
declare module 'autodll-webpack-plugin/lib/mapParentConfig.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/mapParentConfig'>;
}
declare module 'autodll-webpack-plugin/lib/normalizeEntry.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/normalizeEntry'>;
}
declare module 'autodll-webpack-plugin/lib/paths.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/paths'>;
}
declare module 'autodll-webpack-plugin/lib/plugin.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/plugin'>;
}
declare module 'autodll-webpack-plugin/lib/utils/fs.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/utils/fs'>;
}
declare module 'autodll-webpack-plugin/lib/utils/index.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/utils/index'>;
}
declare module 'autodll-webpack-plugin/lib/utils/safeClone.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/utils/safeClone'>;
}
declare module 'autodll-webpack-plugin/lib/validateCache.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/lib/validateCache'>;
}
declare module 'autodll-webpack-plugin/src/createCompileIfNeeded.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/createCompileIfNeeded'>;
}
declare module 'autodll-webpack-plugin/src/createConfig.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/createConfig'>;
}
declare module 'autodll-webpack-plugin/src/createHandleStats.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/createHandleStats'>;
}
declare module 'autodll-webpack-plugin/src/createHash.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/createHash'>;
}
declare module 'autodll-webpack-plugin/src/createLogger.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/createLogger'>;
}
declare module 'autodll-webpack-plugin/src/createMemory.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/createMemory'>;
}
declare module 'autodll-webpack-plugin/src/createSettings.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/createSettings'>;
}
declare module 'autodll-webpack-plugin/src/getEnv.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/getEnv'>;
}
declare module 'autodll-webpack-plugin/src/getInstanceIndex.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/getInstanceIndex'>;
}
declare module 'autodll-webpack-plugin/src/index.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/index'>;
}
declare module 'autodll-webpack-plugin/src/mapParentConfig.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/mapParentConfig'>;
}
declare module 'autodll-webpack-plugin/src/normalizeEntry.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/normalizeEntry'>;
}
declare module 'autodll-webpack-plugin/src/paths.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/paths'>;
}
declare module 'autodll-webpack-plugin/src/plugin.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/plugin'>;
}
declare module 'autodll-webpack-plugin/src/utils/fs.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/utils/fs'>;
}
declare module 'autodll-webpack-plugin/src/utils/index.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/utils/index'>;
}
declare module 'autodll-webpack-plugin/src/utils/safeClone.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/utils/safeClone'>;
}
declare module 'autodll-webpack-plugin/src/validateCache.js' {
declare module.exports: $Exports<'autodll-webpack-plugin/src/validateCache'>;
}
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
"@babel/runtime": "7.0.0-rc.1", "@babel/runtime": "7.0.0-rc.1",
"@babel/template": "7.0.0-rc.1", "@babel/template": "7.0.0-rc.1",
"ansi-html": "0.0.7", "ansi-html": "0.0.7",
"autodll-webpack-plugin": "0.4.2",
"babel-core": "7.0.0-bridge.0", "babel-core": "7.0.0-bridge.0",
"babel-loader": "8.0.0-beta.3", "babel-loader": "8.0.0-beta.3",
"babel-plugin-react-require": "3.0.0", "babel-plugin-react-require": "3.0.0",
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment