1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Apply hot-self-accept to all pageExtensions (#4616)

This makes sure plugins like @zeit/next-typescript or @zeit/next-mdx don't have to provide the `hot-self-accept-loader`.
This fixes for example @zeit/next-mdx, which doesn't implement `pageExtensions` but we do use mdx as top level pages for https://github.com/zeit/docs
This commit is contained in:
Tim Neutkens 2018-06-16 15:51:00 +02:00 committed by GitHub
parent 4d2ca789d2
commit c3866649c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

View file

@ -11,6 +11,14 @@ module.exports = function (content: string, sourceMap: any) {
this.cacheable()
const options: Options = loaderUtils.getOptions(this)
if (!options.extensions) {
throw new Error('extensions is not provided to hot-self-accept-loader. Please upgrade all next-plugins to the latest version.')
}
if (!options.include) {
throw new Error('include option is not provided to hot-self-accept-loader. Please upgrade all next-plugins to the latest version.')
}
const route = getRoute(this.resourcePath, options)
// Webpack has a built in system to prevent default from colliding, giving it a random letter per export.
@ -37,14 +45,6 @@ module.exports = function (content: string, sourceMap: any) {
}
function getRoute (resourcePath: string, options: Options) {
if (!options.extensions) {
throw new Error('extensions is not provided to hot-self-accept-loader. Please upgrade all next-plugins to the latest version.')
}
if (!options.include) {
throw new Error('include option is not provided to hot-self-accept-loader. Please upgrade all next-plugins to the latest version.')
}
const dir = options.include.find((d) => resourcePath.indexOf(d) === 0)
if (!dir) {

View file

@ -60,7 +60,9 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer
include: [
path.join(dir, 'pages')
],
extensions: /\.(js|jsx)$/
// All pages are javascript files. So we apply hot-self-accept-loader here to facilitate hot reloading of pages.
// This makes sure plugins just have to implement `pageExtensions` instead of also implementing the loader
extensions: new RegExp(`\\.+(${config.pageExtensions.join('|')})$`)
}
}
}