From 1985cae46b8e8825024ffd25d2013506670007aa Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Wed, 1 Feb 2017 11:18:11 +0530 Subject: [PATCH 1/2] Fix .json import error This is a regression we've added by #926 (tree-shaking-support) --- server/build/loaders/emit-file-loader.js | 2 +- server/build/webpack.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) 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, From 9b5bda83516010750cf29d9837b3e8c9ebf50b6d Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Wed, 1 Feb 2017 11:22:23 +0530 Subject: [PATCH 2/2] Add a test case. --- test/integration/basic/lib/data.json | 3 +++ test/integration/basic/pages/json.js | 5 +++++ test/integration/basic/test/rendering.js | 5 +++++ 3 files changed, 13 insertions(+) create mode 100644 test/integration/basic/lib/data.json create mode 100644 test/integration/basic/pages/json.js 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/)