Skip to content

Commit 45ac394

Browse files
authored
Merge pull request #77 from dev-five-git/webpack-hmr
Upgrade webpack hmr
2 parents b662467 + dc125a6 commit 45ac394

File tree

5 files changed

+45
-32
lines changed

5 files changed

+45
-32
lines changed

.changeset/curly-readers-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/webpack-plugin": patch
3+
---
4+
5+
Upgrade webpack hmr
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
import { getCss } from '@devup-ui/wasm'
1+
import { resolve } from 'node:path'
22

33
import devupUICssLoader from '../css-loader'
44

5-
vi.mock('@devup-ui/wasm')
5+
vi.mock('node:path')
66

77
describe('devupUICssLoader', () => {
88
it('should invoke callback', () => {
9-
vi.mocked(getCss).mockReturnValue('css')
109
const callback = vi.fn()
10+
const addContextDependency = vi.fn()
11+
vi.mocked(resolve).mockReturnValue('resolved')
1112
devupUICssLoader.bind({
1213
callback,
13-
} as any)(Buffer.from(''), '')
14-
expect(callback).toBeCalledWith(null, 'css')
14+
addContextDependency,
15+
} as any)(Buffer.from('data'), '')
16+
expect(callback).toBeCalledWith(null, Buffer.from('data'))
17+
expect(addContextDependency).toBeCalledWith('resolved')
1518
})
1619
})
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { getCss } from '@devup-ui/wasm'
1+
import { resolve } from 'node:path'
2+
23
import type { RawLoaderDefinitionFunction } from 'webpack'
34

4-
const devupUICssLoader: RawLoaderDefinitionFunction = function () {
5-
this.callback(null, getCss())
5+
const devupUICssLoader: RawLoaderDefinitionFunction = function (a) {
6+
this.addContextDependency(resolve(this.rootContext, 'src'))
7+
this.callback(null, a)
68
}
79
export default devupUICssLoader

packages/webpack-plugin/src/loader.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const devupUILoader: RawLoaderDefinitionFunction<DevupUILoaderOptions> =
2323
callback(null, source)
2424
return
2525
}
26-
this.addDependency(cssFile)
2726

2827
try {
2928
const { code, css } = codeExtract(

packages/webpack-plugin/src/plugin.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,30 +103,34 @@ export class DevupUIWebpackPlugin {
103103
writeFileSync(this.options.cssFile, '', { encoding: 'utf-8' })
104104
}
105105

106-
compiler.options.module.rules.push({
107-
test: this.options.cssFile,
108-
use: [
109-
{
110-
loader: createRequire(import.meta.url).resolve(
111-
'@devup-ui/webpack-plugin/css-loader',
112-
),
113-
},
114-
],
115-
})
106+
compiler.options.module.rules.push(
107+
{
108+
test: /\.(tsx|ts|js|mjs|jsx)$/,
109+
exclude: /node_modules/,
110+
enforce: 'pre',
111+
use: [
112+
{
113+
loader: createRequire(import.meta.url).resolve(
114+
'@devup-ui/webpack-plugin/loader',
115+
),
116+
options: {
117+
plugin: this,
118+
},
119+
},
120+
],
121+
},
122+
{
123+
test: this.options.cssFile,
124+
enforce: 'post',
116125

117-
compiler.options.module.rules.push({
118-
test: /\.(tsx|ts|js|mjs|jsx)$/,
119-
exclude: /node_modules/,
120-
use: [
121-
{
122-
loader: createRequire(import.meta.url).resolve(
123-
'@devup-ui/webpack-plugin/loader',
124-
),
125-
options: {
126-
plugin: this,
126+
use: [
127+
{
128+
loader: createRequire(import.meta.url).resolve(
129+
'@devup-ui/webpack-plugin/css-loader',
130+
),
127131
},
128-
},
129-
],
130-
})
132+
],
133+
},
134+
)
131135
}
132136
}

0 commit comments

Comments
 (0)