From d53ec85fc8129adb74f4dc4b55a45f0b0cbbac9d Mon Sep 17 00:00:00 2001 From: Ives van Hoorne Date: Sun, 30 Oct 2016 22:43:09 +0100 Subject: [PATCH 1/2] Support for jsx --- server/build/webpack.js | 8 ++++---- server/resolve.js | 3 ++- test/fixtures/basic/pages/jsxpage.jsx | 5 +++++ test/index.js | 5 +++++ 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/basic/pages/jsxpage.jsx diff --git a/server/build/webpack.js b/server/build/webpack.js index a7f9bb625a0d2..b6e252a5ea350 100644 --- a/server/build/webpack.js +++ b/server/build/webpack.js @@ -10,7 +10,7 @@ import DynamicEntryPlugin from './plugins/dynamic-entry-plugin' export default async function createCompiler (dir, { hotReload = false } = {}) { dir = resolve(dir) - const pages = await glob('pages/**/*.js', { cwd: dir }) + const pages = await glob('pages/**/*.+(js|jsx)', { cwd: dir }) const entry = {} const defaultEntries = hotReload ? ['webpack/hot/dev-server'] : [] @@ -57,7 +57,7 @@ export default async function createCompiler (dir, { hotReload = false } = {}) { .replace(/[\\\/]package\.json$/, '') const loaders = [{ - test: /\.js$/, + test: /\.jsx?$/, loader: 'emit-file-loader', include: [dir, nextPagesDir], exclude (str) { @@ -68,12 +68,12 @@ export default async function createCompiler (dir, { hotReload = false } = {}) { } }] .concat(hotReload ? [{ - test: /\.js$/, + test: /\.jsx?$/, loader: 'hot-self-accept-loader', include: join(dir, 'pages') }] : []) .concat([{ - test: /\.js$/, + test: /\.jsx?$/, loader: 'babel', include: [dir, nextPagesDir], exclude (str) { diff --git a/server/resolve.js b/server/resolve.js index ca778dfd018ee..160838d29a0c5 100644 --- a/server/resolve.js +++ b/server/resolve.js @@ -25,11 +25,12 @@ export function resolveFromList (id, files) { function getPaths (id) { const i = sep === '/' ? id : id.replace(/\//g, sep) - if (i.slice(-3) === '.js') return [i] + if (i.slice(-3) === '.js' || i.slice(-4) === '.jsx') return [i] if (i[i.length - 1] === sep) return [i + 'index.js'] return [ i + '.js', + i + '.jsx', join(i, 'index.js') ] } diff --git a/test/fixtures/basic/pages/jsxpage.jsx b/test/fixtures/basic/pages/jsxpage.jsx new file mode 100644 index 0000000000000..7420ff6dfd46f --- /dev/null +++ b/test/fixtures/basic/pages/jsxpage.jsx @@ -0,0 +1,5 @@ +import React from 'react' + +export default function () { + return
JSX is found
+} diff --git a/test/index.js b/test/index.js index 8a396305bfcfa..f240b0984cb67 100644 --- a/test/index.js +++ b/test/index.js @@ -34,6 +34,11 @@ test(async t => { t.true(html.includes('

Diego Milito

')) }) +test(async t => { + const html = await render('/jsxpage') + t.true(html.includes('
JSX is found
')) +}) + function render (url, ctx) { return _render(url, ctx, { dir, staticMarkup: true }) } From 8ef579fc71b78dd2a464b8d338daf20a2aa47607 Mon Sep 17 00:00:00 2001 From: Ives van Hoorne Date: Sun, 30 Oct 2016 23:08:54 +0100 Subject: [PATCH 2/2] Support for index.jsx --- server/resolve.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/resolve.js b/server/resolve.js index 160838d29a0c5..a94335501ed0a 100644 --- a/server/resolve.js +++ b/server/resolve.js @@ -26,12 +26,13 @@ function getPaths (id) { const i = sep === '/' ? id : id.replace(/\//g, sep) if (i.slice(-3) === '.js' || i.slice(-4) === '.jsx') return [i] - if (i[i.length - 1] === sep) return [i + 'index.js'] + if (i[i.length - 1] === sep) return [i + 'index.js', i + 'index.jsx'] return [ i + '.js', i + '.jsx', - join(i, 'index.js') + join(i, 'index.js'), + join(i, 'index.jsx') ] }