1
1
import path from 'node:path'
2
2
import gracefulFs from 'graceful-fs'
3
- // import pkg from 'next/dist/compiled/webpack/webpack.js'
4
3
import type { Compiler } from 'webpack'
5
4
import type { NextraConfig } from '../../types'
6
5
import { CHUNKS_DIR , IS_PRODUCTION } from '../constants.js'
7
6
import { PAGES_DIR } from '../file-system.js'
8
7
import { collectPageMap } from '../page-map.js'
9
8
10
- // import { logger } from '../utils'
11
-
12
- // const { webpack, sources } = pkg
13
9
const fs = gracefulFs . promises
14
10
15
11
let isSaved = false
@@ -27,14 +23,6 @@ export class NextraPlugin {
27
23
const { locales, transformPageMap } = this . config
28
24
29
25
compiler . hooks . beforeCompile . tapAsync ( pluginName , async ( _ , callback ) => {
30
- // if (isSaved || !IS_PRODUCTION) {
31
- // // Never call hook 2 times
32
- // // Also on `production` environment we get error:
33
- // // Module not found: Can't resolve '.../.next/static/chunks/nextra-page-map-en.mjs'
34
- // // while using only `processAssets` hook, but without `beforeCompile`
35
- // callback()
36
- // return
37
- // }
38
26
if ( IS_PRODUCTION && isSaved ) {
39
27
callback ( )
40
28
return
@@ -61,46 +49,11 @@ export class NextraPlugin {
61
49
rawJs
62
50
)
63
51
}
64
- // logger.info('`beforeCompile`')
65
52
isSaved = true
66
53
callback ( )
67
54
} catch ( error ) {
68
55
callback ( error as Error )
69
56
}
70
57
} )
71
-
72
- // if (IS_PRODUCTION) {
73
- // // Do not fire `processAssets` on production
74
- // return
75
- // }
76
-
77
- // compiler.hooks.compilation.tap(pluginName, compilation => {
78
- // compilation.hooks.processAssets.tapAsync(
79
- // {
80
- // name: pluginName,
81
- // stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
82
- // },
83
- // async (assets, callback) => {
84
- // try {
85
- // // TODO: Find a way to get filename only for current asset? and get PageMap only for it
86
- // for (const locale of locales) {
87
- // const route = `/${locale}`
88
- // const dir = PAGES_DIR + route
89
- // const rawJs = await collectPageMap({ dir, route })
90
- //
91
- // const assetPath =
92
- // (IS_PRODUCTION ? '../' : '') +
93
- // `../static/chunks/nextra-page-map-${locale}.mjs`
94
- //
95
- // assets[assetPath] = new sources.RawSource(rawJs)
96
- // }
97
- // logger.info('`processAssets`')
98
- // callback()
99
- // } catch (error) {
100
- // callback(error as Error)
101
- // }
102
- // }
103
- // )
104
- // })
105
58
}
106
59
}
0 commit comments