Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
d0754993
Unverified
Commit
d0754993
authored
Aug 22, 2020
by
Tim Neutkens
Committed by
GitHub
Aug 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add webpack 5 caching for css optimizer (#16467)
parent
9acd001e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
39 additions
and
11 deletions
+39
-11
build-manifest-plugin.ts
packages/next/build/webpack/plugins/build-manifest-plugin.ts
+4
-1
css-minimizer-plugin.ts
packages/next/build/webpack/plugins/css-minimizer-plugin.ts
+17
-3
font-stylesheet-gathering-plugin.ts
...build/webpack/plugins/font-stylesheet-gathering-plugin.ts
+4
-1
index.js
...uild/webpack/plugins/mini-css-extract-plugin/src/index.js
+2
-1
nextjs-ssr-module-cache.ts
...ges/next/build/webpack/plugins/nextjs-ssr-module-cache.ts
+4
-1
pages-manifest-plugin.ts
packages/next/build/webpack/plugins/pages-manifest-plugin.ts
+4
-1
react-loadable-plugin.ts
packages/next/build/webpack/plugins/react-loadable-plugin.ts
+4
-3
No files found.
packages/next/build/webpack/plugins/build-manifest-plugin.ts
View file @
d0754993
import
devalue
from
'next/dist/compiled/devalue'
import
devalue
from
'next/dist/compiled/devalue'
import
webpack
,
{
Compiler
,
compilation
as
CompilationType
}
from
'webpack'
import
webpack
,
{
Compiler
,
compilation
as
CompilationType
}
from
'webpack'
import
{
RawSource
}
from
'webpack-sources'
import
sources
from
'webpack-sources'
import
{
import
{
BUILD_MANIFEST
,
BUILD_MANIFEST
,
CLIENT_STATIC_FILES_PATH
,
CLIENT_STATIC_FILES_PATH
,
...
@@ -15,6 +15,9 @@ import { ampFirstEntryNamesMap } from './next-drop-client-page-plugin'
...
@@ -15,6 +15,9 @@ import { ampFirstEntryNamesMap } from './next-drop-client-page-plugin'
import
{
Rewrite
}
from
'../../../lib/load-custom-routes'
import
{
Rewrite
}
from
'../../../lib/load-custom-routes'
import
{
getSortedRoutes
}
from
'../../../next-server/lib/router/utils'
import
{
getSortedRoutes
}
from
'../../../next-server/lib/router/utils'
// @ts-ignore: TODO: remove ignore when webpack 5 is stable
const
{
RawSource
}
=
webpack
.
sources
||
sources
const
isWebpack5
=
parseInt
(
webpack
.
version
!
)
===
5
const
isWebpack5
=
parseInt
(
webpack
.
version
!
)
===
5
type
DeepMutable
<
T
>
=
{
-
readonly
[
P
in
keyof
T
]:
DeepMutable
<
T
[
P
]
>
}
type
DeepMutable
<
T
>
=
{
-
readonly
[
P
in
keyof
T
]:
DeepMutable
<
T
[
P
]
>
}
...
...
packages/next/build/webpack/plugins/css-minimizer-plugin.ts
View file @
d0754993
import
{
process
as
minify
}
from
'cssnano-simple'
import
{
process
as
minify
}
from
'cssnano-simple'
import
webpack
from
'webpack'
import
webpack
from
'webpack'
import
{
RawSource
,
SourceMapSource
}
from
'webpack-sources'
import
sources
from
'webpack-sources'
// @ts-ignore: TODO: remove ignore when webpack 5 is stable
const
{
RawSource
,
SourceMapSource
}
=
webpack
.
sources
||
sources
// https://github.com/NMFR/optimize-css-assets-webpack-plugin/blob/0a410a9bf28c7b0e81a3470a13748e68ca2f50aa/src/index.js#L20
// https://github.com/NMFR/optimize-css-assets-webpack-plugin/blob/0a410a9bf28c7b0e81a3470a13748e68ca2f50aa/src/index.js#L20
const
CSS_REGEX
=
/
\.
css
(\?
.*
)?
$/i
const
CSS_REGEX
=
/
\.
css
(\?
.*
)?
$/i
...
@@ -50,6 +53,7 @@ export class CssMinimizerPlugin {
...
@@ -50,6 +53,7 @@ export class CssMinimizerPlugin {
apply
(
compiler
:
webpack
.
Compiler
)
{
apply
(
compiler
:
webpack
.
Compiler
)
{
compiler
.
hooks
.
compilation
.
tap
(
'CssMinimizerPlugin'
,
(
compilation
:
any
)
=>
{
compiler
.
hooks
.
compilation
.
tap
(
'CssMinimizerPlugin'
,
(
compilation
:
any
)
=>
{
if
(
isWebpack5
)
{
if
(
isWebpack5
)
{
const
cache
=
compilation
.
getCache
(
'CssMinimizerPlugin'
)
compilation
.
hooks
.
processAssets
.
tapPromise
(
compilation
.
hooks
.
processAssets
.
tapPromise
(
{
{
name
:
'CssMinimizerPlugin'
,
name
:
'CssMinimizerPlugin'
,
...
@@ -62,9 +66,19 @@ export class CssMinimizerPlugin {
...
@@ -62,9 +66,19 @@ export class CssMinimizerPlugin {
files
files
.
filter
((
file
)
=>
CSS_REGEX
.
test
(
file
))
.
filter
((
file
)
=>
CSS_REGEX
.
test
(
file
))
.
map
(
async
(
file
)
=>
{
.
map
(
async
(
file
)
=>
{
const
asset
=
compilation
.
assets
[
file
]
const
asset
=
assets
[
file
]
const
etag
=
cache
.
getLazyHashedEtag
(
asset
)
const
cachedResult
=
await
cache
.
getPromise
(
file
,
etag
)
if
(
cachedResult
)
{
assets
[
file
]
=
cachedResult
return
}
assets
[
file
]
=
await
this
.
optimizeAsset
(
file
,
asset
)
const
result
=
await
this
.
optimizeAsset
(
file
,
asset
)
await
cache
.
storePromise
(
file
,
etag
,
result
)
assets
[
file
]
=
result
})
})
)
)
}
}
...
...
packages/next/build/webpack/plugins/font-stylesheet-gathering-plugin.ts
View file @
d0754993
import
webpack
,
{
compilation
as
CompilationType
,
Compiler
}
from
'webpack'
import
webpack
,
{
compilation
as
CompilationType
,
Compiler
}
from
'webpack'
import
{
namedTypes
}
from
'ast-types'
import
{
namedTypes
}
from
'ast-types'
import
{
RawSource
}
from
'webpack-sources'
import
sources
from
'webpack-sources'
import
{
import
{
getFontDefinitionFromNetwork
,
getFontDefinitionFromNetwork
,
FontManifest
,
FontManifest
,
...
@@ -11,6 +11,9 @@ import postcss from 'postcss'
...
@@ -11,6 +11,9 @@ import postcss from 'postcss'
import
minifier
from
'cssnano-simple'
import
minifier
from
'cssnano-simple'
import
{
OPTIMIZED_FONT_PROVIDERS
}
from
'../../../next-server/lib/constants'
import
{
OPTIMIZED_FONT_PROVIDERS
}
from
'../../../next-server/lib/constants'
// @ts-ignore: TODO: remove ignore when webpack 5 is stable
const
{
RawSource
}
=
webpack
.
sources
||
sources
const
isWebpack5
=
parseInt
(
webpack
.
version
!
)
===
5
const
isWebpack5
=
parseInt
(
webpack
.
version
!
)
===
5
async
function
minifyCss
(
css
:
string
):
Promise
<
string
>
{
async
function
minifyCss
(
css
:
string
):
Promise
<
string
>
{
...
...
packages/next/build/webpack/plugins/mini-css-extract-plugin/src/index.js
View file @
d0754993
...
@@ -6,7 +6,8 @@ import sources from 'webpack-sources'
...
@@ -6,7 +6,8 @@ import sources from 'webpack-sources'
import
CssDependency
from
'./CssDependency'
import
CssDependency
from
'./CssDependency'
import
CssModule
from
'./CssModule'
import
CssModule
from
'./CssModule'
const
{
ConcatSource
,
SourceMapSource
,
OriginalSource
}
=
sources
const
{
ConcatSource
,
SourceMapSource
,
OriginalSource
}
=
webpack
.
sources
||
sources
const
{
const
{
Template
,
Template
,
util
:
{
createHash
},
util
:
{
createHash
},
...
...
packages/next/build/webpack/plugins/nextjs-ssr-module-cache.ts
View file @
d0754993
import
webpack
from
'webpack'
import
webpack
from
'webpack'
import
{
RawSource
}
from
'webpack-sources'
import
sources
from
'webpack-sources'
import
{
join
,
relative
,
dirname
}
from
'path'
import
{
join
,
relative
,
dirname
}
from
'path'
import
getRouteFromEntrypoint
from
'../../../next-server/server/get-route-from-entrypoint'
import
getRouteFromEntrypoint
from
'../../../next-server/server/get-route-from-entrypoint'
const
SSR_MODULE_CACHE_FILENAME
=
'ssr-module-cache.js'
const
SSR_MODULE_CACHE_FILENAME
=
'ssr-module-cache.js'
// @ts-ignore: TODO: remove ignore when webpack 5 is stable
const
{
RawSource
}
=
webpack
.
sources
||
sources
// By default webpack keeps initialized modules per-module.
// By default webpack keeps initialized modules per-module.
// This means that if you have 2 entrypoints loaded into the same app
// This means that if you have 2 entrypoints loaded into the same app
// they will *not* share the same instance
// they will *not* share the same instance
...
...
packages/next/build/webpack/plugins/pages-manifest-plugin.ts
View file @
d0754993
import
webpack
,
{
Compiler
,
Plugin
}
from
'webpack'
import
webpack
,
{
Compiler
,
Plugin
}
from
'webpack'
import
{
RawSource
}
from
'webpack-sources'
import
sources
from
'webpack-sources'
import
{
PAGES_MANIFEST
}
from
'../../../next-server/lib/constants'
import
{
PAGES_MANIFEST
}
from
'../../../next-server/lib/constants'
import
getRouteFromEntrypoint
from
'../../../next-server/server/get-route-from-entrypoint'
import
getRouteFromEntrypoint
from
'../../../next-server/server/get-route-from-entrypoint'
export
type
PagesManifest
=
{
[
page
:
string
]:
string
}
export
type
PagesManifest
=
{
[
page
:
string
]:
string
}
// @ts-ignore: TODO: remove ignore when webpack 5 is stable
const
{
RawSource
}
=
webpack
.
sources
||
sources
const
isWebpack5
=
parseInt
(
webpack
.
version
!
)
===
5
const
isWebpack5
=
parseInt
(
webpack
.
version
!
)
===
5
// This plugin creates a pages-manifest.json from page entrypoints.
// This plugin creates a pages-manifest.json from page entrypoints.
...
...
packages/next/build/webpack/plugins/react-loadable-plugin.ts
View file @
d0754993
...
@@ -28,6 +28,9 @@ import webpack, {
...
@@ -28,6 +28,9 @@ import webpack, {
}
from
'webpack'
}
from
'webpack'
import
sources
from
'webpack-sources'
import
sources
from
'webpack-sources'
// @ts-ignore: TODO: remove ignore when webpack 5 is stable
const
{
RawSource
}
=
webpack
.
sources
||
sources
const
isWebpack5
=
parseInt
(
webpack
.
version
!
)
===
5
const
isWebpack5
=
parseInt
(
webpack
.
version
!
)
===
5
function
getModulesIterable
(
compilation
:
any
,
chunk
:
any
)
{
function
getModulesIterable
(
compilation
:
any
,
chunk
:
any
)
{
...
@@ -110,9 +113,7 @@ export class ReactLoadablePlugin {
...
@@ -110,9 +113,7 @@ export class ReactLoadablePlugin {
createAssets
(
compiler
:
any
,
compilation
:
any
,
assets
:
any
)
{
createAssets
(
compiler
:
any
,
compilation
:
any
,
assets
:
any
)
{
const
manifest
=
buildManifest
(
compiler
,
compilation
)
const
manifest
=
buildManifest
(
compiler
,
compilation
)
// @ts-ignore: TODO: remove when webpack 5 is stable
// @ts-ignore: TODO: remove when webpack 5 is stable
assets
[
this
.
filename
]
=
new
(
webpack
.
sources
||
sources
).
RawSource
(
assets
[
this
.
filename
]
=
new
RawSource
(
JSON
.
stringify
(
manifest
,
null
,
2
))
JSON
.
stringify
(
manifest
,
null
,
2
)
)
return
assets
return
assets
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment