mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Make sure hot-self-accept-loader cleans up the route correctly (#4092)
This commit is contained in:
parent
7f335cb032
commit
c3318d8ef6
|
@ -1,9 +1,11 @@
|
||||||
import { resolve, relative } from 'path'
|
import { resolve, relative } from 'path'
|
||||||
|
import loaderUtils from 'loader-utils'
|
||||||
|
|
||||||
module.exports = function (content, sourceMap) {
|
module.exports = function (content, sourceMap) {
|
||||||
this.cacheable()
|
this.cacheable()
|
||||||
|
|
||||||
const route = getRoute(this)
|
const options = loaderUtils.getOptions(this)
|
||||||
|
const route = getRoute(this, options)
|
||||||
|
|
||||||
// Webpack has a built in system to prevent default from colliding, giving it a random letter per export.
|
// Webpack has a built in system to prevent default from colliding, giving it a random letter per export.
|
||||||
// We can safely check if Component is undefined since all other pages imported into the entrypoint don't have __webpack_exports__.default
|
// We can safely check if Component is undefined since all other pages imported into the entrypoint don't have __webpack_exports__.default
|
||||||
|
@ -30,11 +32,16 @@ module.exports = function (content, sourceMap) {
|
||||||
|
|
||||||
const nextPagesDir = resolve(__dirname, '..', '..', '..', 'pages')
|
const nextPagesDir = resolve(__dirname, '..', '..', '..', 'pages')
|
||||||
|
|
||||||
function getRoute (loaderContext) {
|
function getRoute (loaderContext, options) {
|
||||||
const pagesDir = resolve(loaderContext.options.context, 'pages')
|
const pagesDir = resolve(loaderContext.options.context, 'pages')
|
||||||
const { resourcePath } = loaderContext
|
const { resourcePath } = loaderContext
|
||||||
const dir = [pagesDir, nextPagesDir]
|
const dir = [pagesDir, nextPagesDir]
|
||||||
.find((d) => resourcePath.indexOf(d) === 0)
|
.find((d) => resourcePath.indexOf(d) === 0)
|
||||||
const path = relative(dir, resourcePath)
|
|
||||||
|
if (!options.extensions) {
|
||||||
|
throw new Error('extensions is not provided to hot-self-accept-loader. Please upgrade all next-plugins to the latest version.')
|
||||||
|
}
|
||||||
|
|
||||||
|
const path = relative(dir, resourcePath).replace(options.extensions, '.js')
|
||||||
return '/' + path.replace(/((^|\/)index)?\.js$/, '')
|
return '/' + path.replace(/((^|\/)index)?\.js$/, '')
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,15 +177,18 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
dev && !isServer && {
|
dev && !isServer && {
|
||||||
test: /\.(js|jsx)(\?[^?]*)?$/,
|
test: /\.(js|jsx)$/,
|
||||||
loader: 'hot-self-accept-loader',
|
loader: 'hot-self-accept-loader',
|
||||||
include: [
|
include: [
|
||||||
path.join(dir, 'pages'),
|
path.join(dir, 'pages'),
|
||||||
nextPagesDir
|
nextPagesDir
|
||||||
]
|
],
|
||||||
|
options: {
|
||||||
|
extensions: /\.(js|jsx)$/
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.+(js|jsx)$/,
|
test: /\.(js|jsx)$/,
|
||||||
include: [dir],
|
include: [dir],
|
||||||
exclude: /node_modules/,
|
exclude: /node_modules/,
|
||||||
use: defaultLoaders.babel
|
use: defaultLoaders.babel
|
||||||
|
|
Loading…
Reference in a new issue