-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
* CSS Module Support * Fix Server-Side Render of CSS Modules * Fix Jest Snapshots jestjs/jest#8492 * Fix snapshots * Add test for CSS module edit without remounting * Add tests for dev and production style being applied * Add missing TODOs * Include/exclude should only be applied to issuer, not the CSS file itself * Add CSS modules + node_modules tests * Test that content is correct * Create Multi Module Suite * Add client-side navigation support for CSS * Add tests for client-side nav * Add some delays * Try another fix * Increase timeout to 3 minutes * Fix test * Give all unique directories
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import loaderUtils from 'loader-utils' | ||
import path from 'path' | ||
import webpack from 'webpack' | ||
|
||
export function getCssModuleLocalIdent( | ||
context: webpack.loader.LoaderContext, | ||
_: any, | ||
exportName: string, | ||
options: object | ||
) { | ||
const relativePath = path.posix.relative( | ||
context.rootContext, | ||
context.resourcePath | ||
) | ||
|
||
// Generate a more meaningful name (parent folder) when the user names the | ||
// file `index.module.css`. | ||
const fileNameOrFolder = | ||
relativePath.endsWith('index.module.css') && | ||
relativePath !== 'pages/index.module.css' | ||
? '[folder]' | ||
: '[name]' | ||
|
||
// Generate a hash to make the class name unique. | ||
const hash = loaderUtils.getHashDigest( | ||
Buffer.from(`filePath:${relativePath}#className:${exportName}`), | ||
'md5', | ||
'base64', | ||
5 | ||
) | ||
|
||
// Have webpack interpolate the `[folder]` or `[name]` to its real value. | ||
return loaderUtils | ||
.interpolateName( | ||
context, | ||
fileNameOrFolder + '_' + exportName + '__' + hash, | ||
options | ||
) | ||
.replace( | ||
// Webpack name interpolation returns `about.module_root__2oFM9` for | ||
// `.root {}` inside a file named `about.module.css`. Let's simplify | ||
// this. | ||
/\.module_/, | ||
'_' | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { redText } from './index.module.css' | ||
|
||
export default function Home() { | ||
return ( | ||
<div id="verify-red" className={redText}> | ||
This text should be red. | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.redText { | ||
color: red; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { redText } from './index.module.css' | ||
|
||
export default function Home() { | ||
return ( | ||
<div id="verify-red" className={redText}> | ||
This text should be red. | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.redText { | ||
color: red; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { redText } from './index.module.css' | ||
|
||
function Home() { | ||
return ( | ||
<> | ||
<div id="verify-red" className={redText}> | ||
This text should be red. | ||
</div> | ||
<br /> | ||
<input key={'' + Math.random()} id="text-input" type="text" /> | ||
</> | ||
) | ||
} | ||
|
||
export default Home |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.redText { | ||
color: red; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as classes from 'example' | ||
|
||
function Home() { | ||
return <div>This should fail at build time {JSON.stringify(classes)}.</div> | ||
} | ||
|
||
export default Home |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Link from 'next/link' | ||
import { blueText } from './blue.module.css' | ||
|
||
export default function Blue() { | ||
return ( | ||
<> | ||
<div id="verify-blue" className={blueText}> | ||
This text should be blue. | ||
</div> | ||
<br /> | ||
<Link href="/red" prefetch> | ||
<a id="link-red">Red</a> | ||
</Link> | ||
<br /> | ||
<Link href="/none" prefetch={false}> | ||
<a id="link-none">None</a> | ||
</Link> | ||
</> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.blueText { | ||
color: blue; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Link from 'next/link' | ||
|
||
export default function None() { | ||
return ( | ||
<> | ||
<div id="verify-black" style={{ color: 'black' }}> | ||
This text should be black. | ||
</div> | ||
<br /> | ||
<Link href="/red" prefetch={false}> | ||
<a id="link-red">Red</a> | ||
</Link> | ||
<br /> | ||
<Link href="/blue" prefetch={false}> | ||
<a id="link-blue">Blue</a> | ||
</Link> | ||
</> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Link from 'next/link' | ||
import { redText } from './red.module.css' | ||
|
||
export default function Red() { | ||
return ( | ||
<> | ||
<div id="verify-red" className={redText}> | ||
This text should be red. | ||
</div> | ||
<br /> | ||
<Link href="/blue" prefetch={false}> | ||
<a id="link-blue">Blue</a> | ||
</Link> | ||
<br /> | ||
<Link href="/none" prefetch={false}> | ||
<a id="link-none">None</a> | ||
</Link> | ||
</> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.redText { | ||
color: red; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.