File tree Expand file tree Collapse file tree 5 files changed +45
-32
lines changed
packages/webpack-plugin/src Expand file tree Collapse file tree 5 files changed +45
-32
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @devup-ui/webpack-plugin " : patch
3+ ---
4+
5+ Upgrade webpack hmr
Original file line number Diff line number Diff line change 1- import { getCss } from '@devup-ui/wasm '
1+ import { resolve } from 'node:path '
22
33import devupUICssLoader from '../css-loader'
44
5- vi . mock ( '@devup-ui/wasm ' )
5+ vi . mock ( 'node:path ' )
66
77describe ( '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} )
Original file line number Diff line number Diff line change 1- import { getCss } from '@devup-ui/wasm'
1+ import { resolve } from 'node:path'
2+
23import 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}
79export default devupUICssLoader
Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff 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 : / \. ( t s x | t s | j s | m j s | j s x ) $ / ,
109+ exclude : / n o d e _ m o d u l e s / ,
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 : / \. ( t s x | t s | j s | m j s | j s x ) $ / ,
119- exclude : / n o d e _ m o d u l e s / ,
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}
You can’t perform that action at this time.
0 commit comments