Skip to content

Commit ebdf991

Browse files
authored
fix: include css files in handler functions (#1463)
* fix: include css files in handler functions * refactor: explicitly add css files Rather than use a glob pattern to add CSS files to the handler function, explicitly add the same file names listed in required-server-files.json under the "files" key Update the demos/default project in order to test this functionality
1 parent dacf255 commit ebdf991

File tree

6 files changed

+140
-4
lines changed

6 files changed

+140
-4
lines changed

demos/default/next.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ module.exports = {
7878
includePaths: [path.join(__dirname, 'styles-sass-test')],
7979
},
8080
experimental: {
81+
optimizeCss: true,
8182
images: {
8283
remotePatterns: [
8384
{

demos/default/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@types/fs-extra": "^9.0.13",
2929
"@types/jest": "^27.4.1",
3030
"@types/node": "^17.0.25",
31+
"critters": "^0.0.16",
3132
"husky": "^7.0.4",
3233
"if-env": "^1.0.4",
3334
"npm-run-all": "^4.1.5",

package-lock.json

+129-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/src/helpers/config.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ const resolveModuleRoot = (moduleName) => {
7979

8080
const DEFAULT_EXCLUDED_MODULES = ['sharp', 'electron']
8181

82-
export const configureHandlerFunctions = ({ netlifyConfig, publish, ignore = [] }) => {
82+
export const configureHandlerFunctions = async ({ netlifyConfig, publish, ignore = [] }) => {
83+
const config = await getRequiredServerFiles(publish)
84+
const files = config.files || []
85+
const cssFilesToInclude = files.filter((f) => f.startsWith(`${publish}/static/css/`))
86+
8387
/* eslint-disable no-underscore-dangle */
8488
netlifyConfig.functions._ipx ||= {}
8589
netlifyConfig.functions._ipx.node_bundler = 'nft'
@@ -102,6 +106,7 @@ export const configureHandlerFunctions = ({ netlifyConfig, publish, ignore = []
102106
`${publish}/BUILD_ID`,
103107
`${publish}/static/chunks/webpack-middleware*.js`,
104108
`!${publish}/server/**/*.js.nft.json`,
109+
...cssFilesToInclude,
105110
...ignore.map((path) => `!${slash(path)}`),
106111
)
107112

plugin/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const plugin: NetlifyPlugin = {
105105

106106
const buildId = readFileSync(join(publish, 'BUILD_ID'), 'utf8').trim()
107107

108-
configureHandlerFunctions({ netlifyConfig, ignore, publish: relative(process.cwd(), publish) })
108+
await configureHandlerFunctions({ netlifyConfig, ignore, publish: relative(process.cwd(), publish) })
109109

110110
await generateFunctions(constants, appDir)
111111
await generatePagesResolver({ target, constants })

test/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ describe('onBuild()', () => {
454454
'.next/BUILD_ID',
455455
'.next/static/chunks/webpack-middleware*.js',
456456
'!.next/server/**/*.js.nft.json',
457+
".next/static/css/1152424140993be6.css",
458+
".next/static/css/84099ae0bbc955fa.css",
457459
'!../../node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/**/*',
458460
`!node_modules/next/dist/server/lib/squoosh/**/*.wasm`,
459461
`!node_modules/next/dist/next-server/server/lib/squoosh/**/*.wasm`,

0 commit comments

Comments
 (0)