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

JSX extension support #163

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 4 additions & 4 deletions server/build/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'] : []
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions server/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ 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[i.length - 1] === sep) return [i + 'index.js']
if (i.slice(-3) === '.js' || i.slice(-4) === '.jsx') return [i]
if (i[i.length - 1] === sep) return [i + 'index.js', i + 'index.jsx']

return [
i + '.js',
join(i, 'index.js')
i + '.jsx',
join(i, 'index.js'),
join(i, 'index.jsx')
]
}

Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/basic/pages/jsxpage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react'

export default function () {
return <div>JSX is found</div>
}
5 changes: 5 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ test(async t => {
t.true(html.includes('<p>Diego Milito</p>'))
})

test(async t => {
const html = await render('/jsxpage')
t.true(html.includes('<div>JSX is found</div>'))
})

function render (url, ctx) {
return _render(url, ctx, { dir, staticMarkup: true })
}