diff --git a/server/build/loaders/emit-file-loader.js b/server/build/loaders/emit-file-loader.js index e7138d434efda..1a76cd181544a 100644 --- a/server/build/loaders/emit-file-loader.js +++ b/server/build/loaders/emit-file-loader.js @@ -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) } diff --git a/server/build/webpack.js b/server/build/webpack.js index 3399356ac037b..383c182a56cfb 100644 --- a/server/build/webpack.js +++ b/server/build/webpack.js @@ -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, diff --git a/test/integration/basic/lib/data.json b/test/integration/basic/lib/data.json new file mode 100644 index 0000000000000..42ee7df230df2 --- /dev/null +++ b/test/integration/basic/lib/data.json @@ -0,0 +1,3 @@ +{ + "name": "Zeit" +} \ No newline at end of file diff --git a/test/integration/basic/pages/json.js b/test/integration/basic/pages/json.js new file mode 100644 index 0000000000000..348a61d7a6a33 --- /dev/null +++ b/test/integration/basic/pages/json.js @@ -0,0 +1,5 @@ +import data from '../lib/data' + +export default () => ( +
{data.name}
+) diff --git a/test/integration/basic/test/rendering.js b/test/integration/basic/test/rendering.js index ad161ec3b56a1..a99a4c481707c 100644 --- a/test/integration/basic/test/rendering.js +++ b/test/integration/basic/test/rendering.js @@ -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/)