Commit 41cb3b3b authored by JJ Kasper's avatar JJ Kasper Committed by Joe Haddad

Stop PageConfig plugin from running on non-pages (#7884)

* Add test for PageConfig

* Make sure PageConfig plugin is only run for pages
parent 268ac936
......@@ -61,8 +61,11 @@ module.exports = babelLoader.custom(babel => {
customOptions: { isServer, asyncToPromises }
}
) {
const { cwd } = cfg.options
const filename = this.resourcePath
const options = Object.assign({}, cfg.options)
const isPageFile = filename.startsWith(join(cwd, 'pages'))
if (cfg.hasFilesystemConfig()) {
for (const file of [cfg.babelrc, cfg.config]) {
// We only log for client compilation otherwise there will be double output
......@@ -77,7 +80,7 @@ module.exports = babelLoader.custom(babel => {
options.presets = [...options.presets, presetItem]
}
if (!isServer) {
if (!isServer && isPageFile) {
const pageConfigPlugin = babel.createConfigItem(
[require('../../babel/plugins/next-page-config')],
{ type: 'plugin' }
......
import { config as hello } from '../something'
import { config as world } from '../config'
export default () => (
<p>
{hello} {world}
</p>
)
export const config = 'hello'
/* eslint-env jest */
/* global jasmine */
import { join } from 'path'
import { nextBuild } from 'next-test-utils'
const appDir = join(__dirname, '..')
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
describe('Page Config', () => {
it('builds without error when export const config is used outside page', async () => {
const { stderr } = await nextBuild(appDir, undefined, { stderr: true })
expect(stderr).not.toMatch(/Failed to compile\./)
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment