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

Fix .json import issue #944

Merged
merged 2 commits into from
Feb 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/build/loaders/emit-file-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function (content, sourceMap) {
}

if (query.transform) {
const transformed = query.transform({ content, sourceMap })
const transformed = query.transform({ content, sourceMap, interpolatedName })
return emit(transformed.content, transformed.sourceMap)
}

Expand Down
7 changes: 6 additions & 1 deletion server/build/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
// 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.
transform ({ content, sourceMap }) {
transform ({ content, sourceMap, interpolatedName }) {
// Only handle .js files
if (!(/\.js$/.test(interpolatedName))) {
return { content, sourceMap }
}

const transpiled = babelCore.transform(content, {
presets: ['es2015'],
sourceMaps: dev ? 'both' : false,
Expand Down
3 changes: 3 additions & 0 deletions test/integration/basic/lib/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Zeit"
}
5 changes: 5 additions & 0 deletions test/integration/basic/pages/json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import data from '../lib/data'

export default () => (
<div>{data.name}</div>
)
5 changes: 5 additions & 0 deletions test/integration/basic/test/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export default function ({ app }, suiteName, render) {
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 () => {
const $ = await get$('/error')
expect($('pre').text()).toMatch(/This is an expected error/)
Expand Down