Skip to content

Commit

Permalink
Fix preprocessor loader error (#10235)
Browse files Browse the repository at this point in the history
* Run resolve-url-loader after sass-loader

* Add regression test

* Update test to match

* Revert global.ts

* Make `preProcessors` readonly

Co-authored-by: Joe Haddad <timer150@gmail.com>
  • Loading branch information
alejalapeno and Timer committed Jan 28, 2020
1 parent e4a6bab commit bd3662b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
Expand Up @@ -5,8 +5,8 @@ import { getClientStyleLoader } from './client'

export function getGlobalCssLoader(
ctx: ConfigurationContext,
postCssPlugins: postcss.AcceptedPlugin[],
preProcessors: webpack.RuleSetUseItem[] = []
postCssPlugins: readonly postcss.AcceptedPlugin[],
preProcessors: readonly webpack.RuleSetUseItem[] = []
): webpack.RuleSetUseItem[] {
const loaders: webpack.RuleSetUseItem[] = []

Expand Down Expand Up @@ -40,7 +40,7 @@ export function getGlobalCssLoader(
loaders.push(
// Webpack loaders run like a stack, so we need to reverse the natural
// order of preprocessors.
...preProcessors.reverse()
...preProcessors.slice().reverse()
)

return loaders
Expand Down
Expand Up @@ -6,8 +6,8 @@ import { getCssModuleLocalIdent } from './getCssModuleLocalIdent'

export function getCssModuleLoader(
ctx: ConfigurationContext,
postCssPlugins: postcss.AcceptedPlugin[],
preProcessors: webpack.RuleSetUseItem[] = []
postCssPlugins: readonly postcss.AcceptedPlugin[],
preProcessors: readonly webpack.RuleSetUseItem[] = []
): webpack.RuleSetUseItem[] {
const loaders: webpack.RuleSetUseItem[] = []

Expand Down Expand Up @@ -56,7 +56,7 @@ export function getCssModuleLoader(
loaders.push(
// Webpack loaders run like a stack, so we need to reverse the natural
// order of preprocessors.
...preProcessors.reverse()
...preProcessors.slice().reverse()
)

return loaders
Expand Down
12 changes: 12 additions & 0 deletions test/integration/scss-fixtures/loader-order/pages/_app.js
@@ -0,0 +1,12 @@
import React from 'react'
import App from 'next/app'
import '../styles/global.scss'

class MyApp extends App {
render() {
const { Component, pageProps } = this.props
return <Component {...pageProps} />
}
}

export default MyApp
3 changes: 3 additions & 0 deletions test/integration/scss-fixtures/loader-order/pages/index.js
@@ -0,0 +1,3 @@
export default function Home() {
return <div className="red-text">This text should be red.</div>
}
@@ -0,0 +1,6 @@
// Double forward slash comment

$var: red;
.red-text {
color: $var;
}
15 changes: 15 additions & 0 deletions test/integration/scss/test/index.test.js
Expand Up @@ -745,6 +745,21 @@ describe('SCSS Support', () => {
})
})

describe('Preprocessor loader order', () => {
const appDir = join(fixturesDir, 'loader-order')

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

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

describe('Ordering with styled-jsx (dev)', () => {
const appDir = join(fixturesDir, 'with-styled-jsx')

Expand Down

0 comments on commit bd3662b

Please sign in to comment.