1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Fix .json import issue (#944)

* Fix .json import error
This is a regression we've added by #926 (tree-shaking-support)

* Add a test case.
This commit is contained in:
Arunoda Susiripala 2017-02-01 11:47:15 +05:30 committed by Naoyuki Kanezawa
parent 579098663c
commit ec2c8c6784
5 changed files with 20 additions and 2 deletions

View file

@ -16,7 +16,7 @@ module.exports = function (content, sourceMap) {
} }
if (query.transform) { if (query.transform) {
const transformed = query.transform({ content, sourceMap }) const transformed = query.transform({ content, sourceMap, interpolatedName })
return emit(transformed.content, transformed.sourceMap) return emit(transformed.content, transformed.sourceMap)
} }

View file

@ -149,7 +149,12 @@ export default async function createCompiler (dir, { dev = false, quiet = false
// By default, our babel config does not transpile ES2015 module syntax because // By default, our babel config does not transpile ES2015 module syntax because
// webpack knows how to handle them. (That's how it can do tree-shaking) // webpack knows how to handle them. (That's how it can do tree-shaking)
// But Node.js doesn't know how to handle them. So, we have to transpile them here. // But Node.js doesn't know how to handle them. So, we have to transpile them here.
transform ({ content, sourceMap }) { transform ({ content, sourceMap, interpolatedName }) {
// Only handle .js files
if (!(/\.js$/.test(interpolatedName))) {
return { content, sourceMap }
}
const transpiled = babelCore.transform(content, { const transpiled = babelCore.transform(content, {
presets: ['es2015'], presets: ['es2015'],
sourceMaps: dev ? 'both' : false, sourceMaps: dev ? 'both' : false,

View file

@ -0,0 +1,3 @@
{
"name": "Zeit"
}

View file

@ -0,0 +1,5 @@
import data from '../lib/data'
export default () => (
<div>{data.name}</div>
)

View file

@ -61,6 +61,11 @@ export default function ({ app }, suiteName, render) {
expect($('pre').text().includes(expectedErrorMessage)).toBeTruthy() expect($('pre').text().includes(expectedErrorMessage)).toBeTruthy()
}) })
test('allows to import .json files', async () => {
const html = await render('/json')
expect(html.includes('Zeit')).toBeTruthy()
})
test('error', async () => { test('error', async () => {
const $ = await get$('/error') const $ = await get$('/error')
expect($('pre').text()).toMatch(/This is an expected error/) expect($('pre').text()).toMatch(/This is an expected error/)