|
1 | 1 | import * as fs from 'fs'
|
2 | 2 | import colors from 'pintor'
|
3 |
| -import {Compiler} from '@rspack/core' |
| 3 | +import {Compiler, DefinePlugin} from '@rspack/core' |
4 | 4 | import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'
|
5 | 5 | import {EnvPlugin} from './env'
|
6 | 6 | import {CleanDistFolderPlugin} from './clean-dist'
|
@@ -49,51 +49,57 @@ export class CompilationPlugin {
|
49 | 49 | }).apply(compiler)
|
50 | 50 | }
|
51 | 51 |
|
52 |
| - compiler.hooks.done.tapAsync('develop:brand', (stats, done) => { |
53 |
| - stats.compilation.name = undefined |
54 |
| - |
55 |
| - // Calculate compilation time |
56 |
| - const duration = stats.compilation.endTime! - stats.compilation.startTime! |
57 |
| - |
58 |
| - const manifestName = JSON.parse( |
59 |
| - fs.readFileSync(this.manifestPath, 'utf-8') |
60 |
| - ).name |
61 |
| - |
62 |
| - const hasErrors = stats.hasErrors() |
63 |
| - const key = getCompilationKey(manifestName, hasErrors) |
64 |
| - const rawLine = messages.boring(manifestName, duration, stats) |
65 |
| - if (!rawLine) { |
66 |
| - done() |
67 |
| - return |
68 |
| - } |
69 |
| - const line: string = rawLine |
70 |
| - |
71 |
| - // If message repeats, overwrite previous compilation line and append (Nx) |
72 |
| - if (key === lastCompilationKey) { |
73 |
| - repeatCompilationCount += 1 |
74 |
| - const suffix = colors.gray(` (${repeatCompilationCount}x) `) |
75 |
| - |
76 |
| - // In TTY, overwrite only from the 3rd time onward to preserve the first blank line after summary |
77 |
| - if (process.stdout.isTTY && repeatCompilationCount > 2) { |
78 |
| - process.stdout.write('\u001b[1A') |
79 |
| - process.stdout.write('\u001b[2K') |
80 |
| - process.stdout.write(line + suffix + '\n') |
81 |
| - } else { |
82 |
| - console.log(line + suffix) |
| 52 | + ;(new DefinePlugin({ |
| 53 | + 'process.env.NODE_ENV': JSON.stringify( |
| 54 | + compiler.options.mode || 'development' |
| 55 | + ) |
| 56 | + }), |
| 57 | + compiler.hooks.done.tapAsync('develop:brand', (stats, done) => { |
| 58 | + stats.compilation.name = undefined |
| 59 | + |
| 60 | + // Calculate compilation time |
| 61 | + const duration = |
| 62 | + stats.compilation.endTime! - stats.compilation.startTime! |
| 63 | + |
| 64 | + const manifestName = JSON.parse( |
| 65 | + fs.readFileSync(this.manifestPath, 'utf-8') |
| 66 | + ).name |
| 67 | + |
| 68 | + const hasErrors = stats.hasErrors() |
| 69 | + const key = getCompilationKey(manifestName, hasErrors) |
| 70 | + const rawLine = messages.boring(manifestName, duration, stats) |
| 71 | + if (!rawLine) { |
| 72 | + done() |
| 73 | + return |
83 | 74 | }
|
84 |
| - } else { |
85 |
| - // New key: reset counter and print fresh line with newline |
86 |
| - lastCompilationKey = key |
87 |
| - repeatCompilationCount = 1 |
88 |
| - |
89 |
| - // Do not insert extra blank lines; keep messages sequential |
90 |
| - if (!printedFirstCompilation) { |
91 |
| - printedFirstCompilation = true |
| 75 | + const line: string = rawLine |
| 76 | + |
| 77 | + // If message repeats, overwrite previous compilation line and append (Nx) |
| 78 | + if (key === lastCompilationKey) { |
| 79 | + repeatCompilationCount += 1 |
| 80 | + const suffix = colors.gray(` (${repeatCompilationCount}x) `) |
| 81 | + |
| 82 | + // In TTY, overwrite only from the 3rd time onward to preserve the first blank line after summary |
| 83 | + if (process.stdout.isTTY && repeatCompilationCount > 2) { |
| 84 | + process.stdout.write('\u001b[1A') |
| 85 | + process.stdout.write('\u001b[2K') |
| 86 | + process.stdout.write(line + suffix + '\n') |
| 87 | + } else { |
| 88 | + console.log(line + suffix) |
| 89 | + } |
| 90 | + } else { |
| 91 | + // New key: reset counter and print fresh line with newline |
| 92 | + lastCompilationKey = key |
| 93 | + repeatCompilationCount = 1 |
| 94 | + |
| 95 | + // Do not insert extra blank lines; keep messages sequential |
| 96 | + if (!printedFirstCompilation) { |
| 97 | + printedFirstCompilation = true |
| 98 | + } |
| 99 | + console.log(line) |
92 | 100 | }
|
93 |
| - console.log(line) |
94 |
| - } |
95 | 101 |
|
96 |
| - done() |
97 |
| - }) |
| 102 | + done() |
| 103 | + })) |
98 | 104 | }
|
99 | 105 | }
|
0 commit comments