Skip to content

Commit

Permalink
Merge branch 'canary' into fix/hmr-bluebird
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk authored Oct 9, 2019
2 parents 0d55c5a + e5202ff commit 18a7cd9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
8 changes: 4 additions & 4 deletions README-zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default () => <div>Welcome to next.js!</div>
- 自动打包编译 (使用 webpack 和 babel)
- 热加载
-`./pages`作为服务的渲染和索引
- 静态文件服务. `./static/` 映射到 `/static/` (可以 [创建一个静态目录](#static-file-serving-eg-images) 在你的项目中)
- 静态文件服务. `./public/` 映射到 `/` (可以 [创建一个静态目录](#static-file-serving-eg-images) 在你的项目中)

这里有个简单的案例,可以下载看看 [sample app - nextgram](https://github.com/zeit/nextgram)

Expand Down Expand Up @@ -227,13 +227,13 @@ export default () => <p style={{ color: 'red' }}>hi there</p>

### 静态文件服务(如图像)

在根目录下新建文件夹叫`static`。代码可以通过`/static/`来引入相关的静态资源。
在根目录下新建文件夹叫`public`。代码可以通过`/`来引入相关的静态资源。

```jsx
export default () => <img src="/static/my-image.png" alt="my image" />
export default () => <img src="/my-image.png" alt="my image" />
```

_注意:不要自定义静态文件夹的名字,只能叫`static` ,因为只有这个名字 Next.js 才会把它当作静态资源。_
_注意:不要自定义静态文件夹的名字,只能叫`public` ,因为只有这个名字 Next.js 才会把它当作静态资源。_

<a id="populating-head" style="display: none"></a>

Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ export default async function getBaseWebpackConfig(
'Custom <App>'
)}. Please move all global CSS imports to ${chalk.cyan(
customAppFile
? path.relative(pagesDir, customAppFile)
? path.relative(dir, customAppFile)
: 'pages/_app.js'
)}.\n` +
`Read more: https://err.sh/next.js/global-css`,
Expand Down
12 changes: 12 additions & 0 deletions test/integration/css/fixtures/single-global-src/src/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react'
import App from 'next/app'
import '../../styles/global.css'

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

export default MyApp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Home () {
return <div className='red-text'>This text should be red.</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.red-text {
color: red;
}
32 changes: 30 additions & 2 deletions test/integration/css/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@ describe('CSS Support', () => {
})
})

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

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

it('should build successfully', async () => {
await nextBuild(appDir)
})

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('Multi Global Support', () => {
const appDir = join(fixturesDir, 'multi-global')

Expand Down Expand Up @@ -194,7 +218,9 @@ describe('CSS Support', () => {
})
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('styles/global.css')
expect(stderr).toContain('Please move all global CSS imports')
expect(stderr).toMatch(
/Please move all global CSS imports.*?pages(\/|\\)_app/
)
})
})

Expand All @@ -211,7 +237,9 @@ describe('CSS Support', () => {
})
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('styles/global.css')
expect(stderr).toContain('Please move all global CSS imports')
expect(stderr).toMatch(
/Please move all global CSS imports.*?pages(\/|\\)_app/
)
})
})

Expand Down

0 comments on commit 18a7cd9

Please sign in to comment.