-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JS wrapper to CSS to support Serverless target
Resolves #281
- Loading branch information
1 parent
6eeed21
commit 52f2dd5
Showing
4 changed files
with
32 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Serverless target in Next.js does work if you try to read in files at runtime | ||
// that are not JavaScript or JSON (e.g. CSS files). | ||
// https://github.com/iaincollins/next-auth/issues/281 | ||
// | ||
// To work around this issue, this script is a manual step that wraps CSS in a | ||
// JavaScript file that has the compiled CSS embedded in it, and exports only | ||
// a function that returns the CSS as a string. | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const pathToCssJs = path.join(__dirname, '../dist/css/index.js') | ||
const pathToCss = path.join(__dirname, '../dist/css/index.css') | ||
|
||
const css = fs.readFileSync(pathToCss, 'utf8') | ||
const cssWithEscapedQuotes = css.replace(/"/gm, '\\"') | ||
const js = `module.exports = function() { return "${cssWithEscapedQuotes}" }` | ||
|
||
fs.writeFileSync(pathToCssJs, js) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// To support serverless targets (which don't work if you try to read in things | ||
// like CSS files at run time) this file is replaced in production builds with | ||
// a function that returns compiled CSS (embedded as a string in the function). | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
const pathToCss = path.join(__dirname, '/index.css') | ||
const css = fs.readFileSync(pathToCss, 'utf8') | ||
|
||
export default () => css |
This file contains 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
52f2dd5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: