@@ -68,39 +68,41 @@ func WithResolver(resolver cssc.Resolver) Option {
68
68
}
69
69
70
70
// Plugin is an esbuild plugin for importing .css files.
71
- func Plugin (opts ... Option ) func (api.Plugin ) {
72
- return func (plugin api.Plugin ) {
73
- plugin .SetName ("cssc" )
74
- plugin .AddLoader (
75
- api.LoaderOptions {Filter : `\.css$` },
76
- func (args api.LoaderArgs ) (res api.LoaderResult , err error ) {
77
- res .Loader = api .LoaderCSS
78
-
79
- var errors csscReporter
80
- options := cssc.Options {
81
- Entry : []string {args .Path },
82
- Reporter : & errors ,
83
- }
84
- for _ , opt := range opts {
85
- options = opt (options )
86
- }
87
-
88
- result := cssc .Compile (options )
89
-
90
- if len (errors ) > 0 {
91
- res .Errors = errors .toEsbuild ()
92
- return
93
- }
94
-
95
- f , ok := result .Files [args .Path ]
96
- if ! ok {
97
- err = oops .Errorf ("cssc output did not contain %s" , args .Path )
98
- return
99
- }
100
-
101
- res .Contents = & f
102
- return res , nil
103
- },
104
- )
71
+ func Plugin (opts ... Option ) api.Plugin {
72
+ return api.Plugin {
73
+ Name : "cssc" ,
74
+ Setup : func (build api.PluginBuild ) {
75
+ build .OnLoad (
76
+ api.OnLoadOptions {Filter : `\.css$` },
77
+ func (args api.OnLoadArgs ) (res api.OnLoadResult , err error ) {
78
+ res .Loader = api .LoaderCSS
79
+
80
+ var errors csscReporter
81
+ options := cssc.Options {
82
+ Entry : []string {args .Path },
83
+ Reporter : & errors ,
84
+ }
85
+ for _ , opt := range opts {
86
+ options = opt (options )
87
+ }
88
+
89
+ result := cssc .Compile (options )
90
+
91
+ if len (errors ) > 0 {
92
+ res .Errors = errors .toEsbuild ()
93
+ return
94
+ }
95
+
96
+ f , ok := result .Files [args .Path ]
97
+ if ! ok {
98
+ err = oops .Errorf ("cssc output did not contain %s" , args .Path )
99
+ return
100
+ }
101
+
102
+ res .Contents = & f
103
+ return res , nil
104
+ },
105
+ )
106
+ },
105
107
}
106
108
}
0 commit comments