mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
53a2c5a7fc
* Propagate source maps through combine assets step * Use constant development build id * Move combine assets step before uglify step This ensures that uglify will catch these changes. * Move dynamic chunks step before uglify step This ensures that uglify will catch these changes. * Use chunk templates for page and dynamic chunks This is a little more in line with how webpack generates its bootstrap and should have better compatibility with other plugins and source map generation. * Register combined source map with chunks This ensures that a sourcemap is fully generated. * Do not minimize combined map inputs
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
import { ConcatSource } from 'webpack-sources'
|
|
import {
|
|
IS_BUNDLED_PAGE,
|
|
MATCH_ROUTE_NAME
|
|
} from '../../utils'
|
|
|
|
class PageChunkTemplatePlugin {
|
|
apply (chunkTemplate) {
|
|
chunkTemplate.plugin('render', function (modules, chunk) {
|
|
if (!IS_BUNDLED_PAGE.test(chunk.name)) {
|
|
return modules
|
|
}
|
|
|
|
let routeName = MATCH_ROUTE_NAME.exec(chunk.name)[1]
|
|
|
|
// We need to convert \ into / when we are in windows
|
|
// to get the proper route name
|
|
// Here we need to do windows check because it's possible
|
|
// to have "\" in the filename in unix.
|
|
// Anyway if someone did that, he'll be having issues here.
|
|
// But that's something we cannot avoid.
|
|
if (/^win/.test(process.platform)) {
|
|
routeName = routeName.replace(/\\/g, '/')
|
|
}
|
|
|
|
routeName = `/${routeName.replace(/(^|\/)index$/, '')}`
|
|
|
|
const source = new ConcatSource()
|
|
|
|
source.add(`
|
|
__NEXT_REGISTER_PAGE('${routeName}', function() {
|
|
var comp =
|
|
`)
|
|
source.add(modules)
|
|
source.add(`
|
|
return { page: comp.default }
|
|
})
|
|
`)
|
|
|
|
return source
|
|
})
|
|
}
|
|
}
|
|
|
|
export default class PagesPlugin {
|
|
apply (compiler) {
|
|
compiler.plugin('compilation', (compilation) => {
|
|
compilation.chunkTemplate.apply(new PageChunkTemplatePlugin())
|
|
})
|
|
}
|
|
}
|