Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for sass-loader prependData option #12277

Merged
merged 14 commits into from
May 23, 2020
Merged
5 changes: 4 additions & 1 deletion packages/next/build/webpack/config/blocks/css/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const css = curry(async function css(
ctx: ConfigurationContext,
config: Configuration
) {
const { prependData: sassPrependData, ...sassOptions } = ctx.sassOptions

const sassPreprocessors: webpack.RuleSetUseItem[] = [
// First, process files with `sass-loader`: this inlines content, and
// compiles away the proprietary syntax.
Expand All @@ -37,7 +39,8 @@ export const css = curry(async function css(
// Source maps are required so that `resolve-url-loader` can locate
// files original to their source directory.
sourceMap: true,
sassOptions: ctx.sassOptions,
sassOptions,
prependData: sassPrependData,
},
},
// Then, `sass-loader` will have passed-through CSS imports as-is instead
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
sassOptions: {
prependData: `
$var: red;
`,
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { redText } from './index.module.scss'

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: $var;
}
28 changes: 28 additions & 0 deletions test/integration/scss/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,34 @@ describe('SCSS Support', () => {
})
})

describe('Basic Module Prepend Data Support', () => {
const appDir = join(fixturesDir, 'basic-module-prepend-data')

beforeAll(async () => {
await remove(join(appDir, '.next'))
})

it('should compile successfully', async () => {
const { code, stdout } = await nextBuild(appDir, [], {
stdout: true,
})
expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/)
})

it(`should've emitted a single CSS file`, async () => {
const cssFolder = join(appDir, '.next/static/css')

const files = await readdir(cssFolder)
const cssFiles = files.filter((f) => /\.css$/.test(f))

expect(cssFiles.length).toBe(1)
expect(await readFile(join(cssFolder, cssFiles[0]), 'utf8')).toContain(
'color:red'
)
})
})

describe('Basic Global Support with src/ dir', () => {
const appDir = join(fixturesDir, 'single-global-src')

Expand Down