@o.z/vite-plugin-swc 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +1 -283
- package/dist/index.js +1 -283
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -5,289 +5,7 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
|
|
|
5
5
|
const pluginutils = require('@rollup/pluginutils');
|
|
6
6
|
const core = require('@swc/core');
|
|
7
7
|
|
|
8
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key,
|
|
9
|
-
try {
|
|
10
|
-
var info = gen[key](arg);
|
|
11
|
-
var value = info.value;
|
|
12
|
-
} catch (error) {
|
|
13
|
-
reject(error);
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
if (info.done) {
|
|
17
|
-
resolve(value);
|
|
18
|
-
} else {
|
|
19
|
-
Promise.resolve(value).then(_next, _throw);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function _async_to_generator(fn) {
|
|
23
|
-
return function() {
|
|
24
|
-
var self = this, args = arguments;
|
|
25
|
-
return new Promise(function(resolve, reject) {
|
|
26
|
-
var gen = fn.apply(self, args);
|
|
27
|
-
function _next(value) {
|
|
28
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
29
|
-
}
|
|
30
|
-
function _throw(err) {
|
|
31
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
32
|
-
}
|
|
33
|
-
_next(undefined);
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function _define_property(obj, key, value) {
|
|
38
|
-
if (key in obj) {
|
|
39
|
-
Object.defineProperty(obj, key, {
|
|
40
|
-
value: value,
|
|
41
|
-
enumerable: true,
|
|
42
|
-
configurable: true,
|
|
43
|
-
writable: true
|
|
44
|
-
});
|
|
45
|
-
} else {
|
|
46
|
-
obj[key] = value;
|
|
47
|
-
}
|
|
48
|
-
return obj;
|
|
49
|
-
}
|
|
50
|
-
function _object_spread(target) {
|
|
51
|
-
for(var i = 1; i < arguments.length; i++){
|
|
52
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
53
|
-
var ownKeys = Object.keys(source);
|
|
54
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
55
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
56
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
ownKeys.forEach(function(key) {
|
|
60
|
-
_define_property(target, key, source[key]);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
return target;
|
|
64
|
-
}
|
|
65
|
-
function _object_without_properties(source, excluded) {
|
|
66
|
-
if (source == null) return {};
|
|
67
|
-
var target = {}, sourceKeys, key, i;
|
|
68
|
-
if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
|
|
69
|
-
sourceKeys = Reflect.ownKeys(source);
|
|
70
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
71
|
-
key = sourceKeys[i];
|
|
72
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
73
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
74
|
-
target[key] = source[key];
|
|
75
|
-
}
|
|
76
|
-
return target;
|
|
77
|
-
}
|
|
78
|
-
target = _object_without_properties_loose(source, excluded);
|
|
79
|
-
if (Object.getOwnPropertySymbols) {
|
|
80
|
-
sourceKeys = Object.getOwnPropertySymbols(source);
|
|
81
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
82
|
-
key = sourceKeys[i];
|
|
83
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
84
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
85
|
-
target[key] = source[key];
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return target;
|
|
89
|
-
}
|
|
90
|
-
function _object_without_properties_loose(source, excluded) {
|
|
91
|
-
if (source == null) return {};
|
|
92
|
-
var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
|
|
93
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
94
|
-
key = sourceKeys[i];
|
|
95
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
96
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
97
|
-
target[key] = source[key];
|
|
98
|
-
}
|
|
99
|
-
return target;
|
|
100
|
-
}
|
|
101
|
-
function _ts_generator(thisArg, body) {
|
|
102
|
-
var f, y, t, _ = {
|
|
103
|
-
label: 0,
|
|
104
|
-
sent: function() {
|
|
105
|
-
if (t[0] & 1) throw t[1];
|
|
106
|
-
return t[1];
|
|
107
|
-
},
|
|
108
|
-
trys: [],
|
|
109
|
-
ops: []
|
|
110
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
111
|
-
return d(g, "next", {
|
|
112
|
-
value: verb(0)
|
|
113
|
-
}), d(g, "throw", {
|
|
114
|
-
value: verb(1)
|
|
115
|
-
}), d(g, "return", {
|
|
116
|
-
value: verb(2)
|
|
117
|
-
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
118
|
-
value: function() {
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
}), g;
|
|
122
|
-
function verb(n) {
|
|
123
|
-
return function(v) {
|
|
124
|
-
return step([
|
|
125
|
-
n,
|
|
126
|
-
v
|
|
127
|
-
]);
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
function step(op) {
|
|
131
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
132
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
133
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
134
|
-
if (y = 0, t) op = [
|
|
135
|
-
op[0] & 2,
|
|
136
|
-
t.value
|
|
137
|
-
];
|
|
138
|
-
switch(op[0]){
|
|
139
|
-
case 0:
|
|
140
|
-
case 1:
|
|
141
|
-
t = op;
|
|
142
|
-
break;
|
|
143
|
-
case 4:
|
|
144
|
-
_.label++;
|
|
145
|
-
return {
|
|
146
|
-
value: op[1],
|
|
147
|
-
done: false
|
|
148
|
-
};
|
|
149
|
-
case 5:
|
|
150
|
-
_.label++;
|
|
151
|
-
y = op[1];
|
|
152
|
-
op = [
|
|
153
|
-
0
|
|
154
|
-
];
|
|
155
|
-
continue;
|
|
156
|
-
case 7:
|
|
157
|
-
op = _.ops.pop();
|
|
158
|
-
_.trys.pop();
|
|
159
|
-
continue;
|
|
160
|
-
default:
|
|
161
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
162
|
-
_ = 0;
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
166
|
-
_.label = op[1];
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
170
|
-
_.label = t[1];
|
|
171
|
-
t = op;
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
if (t && _.label < t[2]) {
|
|
175
|
-
_.label = t[2];
|
|
176
|
-
_.ops.push(op);
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
if (t[2]) _.ops.pop();
|
|
180
|
-
_.trys.pop();
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
op = body.call(thisArg, _);
|
|
184
|
-
} catch (e) {
|
|
185
|
-
op = [
|
|
186
|
-
6,
|
|
187
|
-
e
|
|
188
|
-
];
|
|
189
|
-
y = 0;
|
|
190
|
-
} finally{
|
|
191
|
-
f = t = 0;
|
|
192
|
-
}
|
|
193
|
-
if (op[0] & 5) throw op[1];
|
|
194
|
-
return {
|
|
195
|
-
value: op[0] ? op[1] : void 0,
|
|
196
|
-
done: true
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Vite plugin that transforms TypeScript and JavaScript files using SWC.
|
|
202
|
-
* It disables Vite's default esbuild transform to let SWC handle the compilation,
|
|
203
|
-
* resulting in significantly faster builds, especially for large codebases.
|
|
204
|
-
*
|
|
205
|
-
* @example
|
|
206
|
-
* ```ts
|
|
207
|
-
* // vite.config.ts
|
|
208
|
-
* import { defineConfig } from 'vite'
|
|
209
|
-
* import swc from '@o.z/vite-plugin-swc'
|
|
210
|
-
*
|
|
211
|
-
* export default defineConfig({
|
|
212
|
-
* plugins: [swc()]
|
|
213
|
-
* })
|
|
214
|
-
* ```
|
|
215
|
-
*
|
|
216
|
-
* @param options - Configuration options for the plugin and SWC.
|
|
217
|
-
* @returns A Vite plugin instance.
|
|
218
|
-
*/ var swc = function swc() {
|
|
219
|
-
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
220
|
-
// Default include/exclude patterns – now covering .ts, .tsx, .js, .jsx
|
|
221
|
-
var _options_include = options.include, include = _options_include === void 0 ? /\.(ts|tsx|js|jsx)$/ : _options_include, _options_exclude = options.exclude, exclude = _options_exclude === void 0 ? "node_modules" : _options_exclude, swcOptions = _object_without_properties(options, [
|
|
222
|
-
"include",
|
|
223
|
-
"exclude"
|
|
224
|
-
]);
|
|
225
|
-
var filter = pluginutils.createFilter(include, exclude);
|
|
226
|
-
return {
|
|
227
|
-
name: "vite-plugin-swc",
|
|
228
|
-
enforce: "pre",
|
|
229
|
-
config: function config() {
|
|
230
|
-
return {
|
|
231
|
-
esbuild: false
|
|
232
|
-
};
|
|
233
|
-
},
|
|
234
|
-
transform: function transform(code, id) {
|
|
235
|
-
return _async_to_generator(function() {
|
|
236
|
-
var _this_environment_config_css, sourceMaps, result, error;
|
|
237
|
-
return _ts_generator(this, function(_state) {
|
|
238
|
-
switch(_state.label){
|
|
239
|
-
case 0:
|
|
240
|
-
if (!filter(id)) return [
|
|
241
|
-
2,
|
|
242
|
-
null
|
|
243
|
-
];
|
|
244
|
-
_state.label = 1;
|
|
245
|
-
case 1:
|
|
246
|
-
_state.trys.push([
|
|
247
|
-
1,
|
|
248
|
-
3,
|
|
249
|
-
,
|
|
250
|
-
4
|
|
251
|
-
]);
|
|
252
|
-
// Determine if source maps should be generated based on Vite's config
|
|
253
|
-
// `this.environment.config` is available inside the transform hook
|
|
254
|
-
sourceMaps = this.environment.config.command === "build" ? !!this.environment.config.build.sourcemap : !!((_this_environment_config_css = this.environment.config.css) === null || _this_environment_config_css === void 0 ? void 0 : _this_environment_config_css.devSourcemap); // For dev, you might want to align with css sourcemaps or a dedicated flag
|
|
255
|
-
return [
|
|
256
|
-
4,
|
|
257
|
-
core.transform(code, _object_spread({
|
|
258
|
-
filename: id,
|
|
259
|
-
sourceFileName: id.split("?", 1)[0],
|
|
260
|
-
sourceMaps: sourceMaps
|
|
261
|
-
}, swcOptions))
|
|
262
|
-
];
|
|
263
|
-
case 2:
|
|
264
|
-
result = _state.sent();
|
|
265
|
-
// SWC returns { code, map } when sourceMaps are enabled, otherwise just { code }
|
|
266
|
-
return [
|
|
267
|
-
2,
|
|
268
|
-
{
|
|
269
|
-
code: result.code,
|
|
270
|
-
map: result.map
|
|
271
|
-
}
|
|
272
|
-
];
|
|
273
|
-
case 3:
|
|
274
|
-
error = _state.sent();
|
|
275
|
-
// Enhance error message with file information and re-throw as a plugin error
|
|
276
|
-
this.error("SWC transform failed in ".concat(id, ": ").concat((error === null || error === void 0 ? void 0 : error.message) || error));
|
|
277
|
-
return [
|
|
278
|
-
3,
|
|
279
|
-
4
|
|
280
|
-
];
|
|
281
|
-
case 4:
|
|
282
|
-
return [
|
|
283
|
-
2
|
|
284
|
-
];
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
}).call(this);
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
};
|
|
8
|
+
function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return}if(info.done){resolve(value);}else {Promise.resolve(value).then(_next,_throw);}}function _async_to_generator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);})}}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else {obj[key]=value;}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}));}ownKeys.forEach(function(key){_define_property(target,key,source[key]);});}return target}function _object_without_properties(source,excluded){if(source==null)return {};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return {};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}return target}function _ts_generator(thisArg,body){var f,y,t,_={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},g=Object.create((typeof Iterator==="function"?Iterator:Object).prototype),d=Object.defineProperty;return d(g,"next",{value:verb(0)}),d(g,"throw",{value:verb(1)}),d(g,"return",{value:verb(2)}),typeof Symbol==="function"&&d(g,Symbol.iterator,{value:function(){return this}}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(g&&(g=0,op[0]&&(_=0)),_)try{if(f=1,y&&(t=op[0]&2?y["return"]:op[0]?y["throw"]||((t=y["return"])&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return {value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(op[0]===6&&_.label<t[1]){_.label=t[1];t=op;break}if(t&&_.label<t[2]){_.label=t[2];_.ops.push(op);break}if(t[2])_.ops.pop();_.trys.pop();continue}op=body.call(thisArg,_);}catch(e){op=[6,e];y=0;}finally{f=t=0;}if(op[0]&5)throw op[1];return {value:op[0]?op[1]:void 0,done:true}}}var swc=function swc(){var options=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{swcrc:false,configFile:false,minify:true,jsc:{parser:{syntax:"typescript",decorators:true},transform:{decoratorMetadata:true,decoratorVersion:"2022-03"}}};var _options_include=options.include,include=_options_include===void 0?/\.(ts|tsx|js|jsx)$/:_options_include,_options_exclude=options.exclude,exclude=_options_exclude===void 0?"node_modules":_options_exclude,swcOptions=_object_without_properties(options,["include","exclude"]);var filter=pluginutils.createFilter(include,exclude);return {name:"vite-plugin-swc",enforce:"pre",config:function config(){return {esbuild:false}},transform:function transform(code,id){return _async_to_generator(function(){var _this_environment_config_css,sourceMaps,result,error;return _ts_generator(this,function(_state){switch(_state.label){case 0:if(!filter(id))return [2,null];_state.label=1;case 1:_state.trys.push([1,3,,4]);sourceMaps=this.environment.config.command==="build"?!!this.environment.config.build.sourcemap:!!((_this_environment_config_css=this.environment.config.css)===null||_this_environment_config_css===void 0?void 0:_this_environment_config_css.devSourcemap);return [4,core.transform(code,_object_spread({filename:id,sourceFileName:id.split("?",1)[0],sourceMaps:sourceMaps},swcOptions))];case 2:result=_state.sent();return [2,{code:result.code,map:result.map}];case 3:error=_state.sent();this.error("SWC transform failed in ".concat(id,": ").concat((error===null||error===void 0?void 0:error.message)||error));return [3,4];case 4:return [2]}})}).call(this)}}};
|
|
291
9
|
|
|
292
10
|
exports.default = swc;
|
|
293
11
|
exports.swc = swc;
|
package/dist/index.js
CHANGED
|
@@ -1,288 +1,6 @@
|
|
|
1
1
|
import { createFilter } from '@rollup/pluginutils';
|
|
2
2
|
import { transform } from '@swc/core';
|
|
3
3
|
|
|
4
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key,
|
|
5
|
-
try {
|
|
6
|
-
var info = gen[key](arg);
|
|
7
|
-
var value = info.value;
|
|
8
|
-
} catch (error) {
|
|
9
|
-
reject(error);
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
if (info.done) {
|
|
13
|
-
resolve(value);
|
|
14
|
-
} else {
|
|
15
|
-
Promise.resolve(value).then(_next, _throw);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function _async_to_generator(fn) {
|
|
19
|
-
return function() {
|
|
20
|
-
var self = this, args = arguments;
|
|
21
|
-
return new Promise(function(resolve, reject) {
|
|
22
|
-
var gen = fn.apply(self, args);
|
|
23
|
-
function _next(value) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
25
|
-
}
|
|
26
|
-
function _throw(err) {
|
|
27
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
28
|
-
}
|
|
29
|
-
_next(undefined);
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function _define_property(obj, key, value) {
|
|
34
|
-
if (key in obj) {
|
|
35
|
-
Object.defineProperty(obj, key, {
|
|
36
|
-
value: value,
|
|
37
|
-
enumerable: true,
|
|
38
|
-
configurable: true,
|
|
39
|
-
writable: true
|
|
40
|
-
});
|
|
41
|
-
} else {
|
|
42
|
-
obj[key] = value;
|
|
43
|
-
}
|
|
44
|
-
return obj;
|
|
45
|
-
}
|
|
46
|
-
function _object_spread(target) {
|
|
47
|
-
for(var i = 1; i < arguments.length; i++){
|
|
48
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
49
|
-
var ownKeys = Object.keys(source);
|
|
50
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
51
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
52
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
53
|
-
}));
|
|
54
|
-
}
|
|
55
|
-
ownKeys.forEach(function(key) {
|
|
56
|
-
_define_property(target, key, source[key]);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
return target;
|
|
60
|
-
}
|
|
61
|
-
function _object_without_properties(source, excluded) {
|
|
62
|
-
if (source == null) return {};
|
|
63
|
-
var target = {}, sourceKeys, key, i;
|
|
64
|
-
if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
|
|
65
|
-
sourceKeys = Reflect.ownKeys(source);
|
|
66
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
67
|
-
key = sourceKeys[i];
|
|
68
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
69
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
70
|
-
target[key] = source[key];
|
|
71
|
-
}
|
|
72
|
-
return target;
|
|
73
|
-
}
|
|
74
|
-
target = _object_without_properties_loose(source, excluded);
|
|
75
|
-
if (Object.getOwnPropertySymbols) {
|
|
76
|
-
sourceKeys = Object.getOwnPropertySymbols(source);
|
|
77
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
78
|
-
key = sourceKeys[i];
|
|
79
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
80
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
81
|
-
target[key] = source[key];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return target;
|
|
85
|
-
}
|
|
86
|
-
function _object_without_properties_loose(source, excluded) {
|
|
87
|
-
if (source == null) return {};
|
|
88
|
-
var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
|
|
89
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
90
|
-
key = sourceKeys[i];
|
|
91
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
92
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
93
|
-
target[key] = source[key];
|
|
94
|
-
}
|
|
95
|
-
return target;
|
|
96
|
-
}
|
|
97
|
-
function _ts_generator(thisArg, body) {
|
|
98
|
-
var f, y, t, _ = {
|
|
99
|
-
label: 0,
|
|
100
|
-
sent: function() {
|
|
101
|
-
if (t[0] & 1) throw t[1];
|
|
102
|
-
return t[1];
|
|
103
|
-
},
|
|
104
|
-
trys: [],
|
|
105
|
-
ops: []
|
|
106
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
107
|
-
return d(g, "next", {
|
|
108
|
-
value: verb(0)
|
|
109
|
-
}), d(g, "throw", {
|
|
110
|
-
value: verb(1)
|
|
111
|
-
}), d(g, "return", {
|
|
112
|
-
value: verb(2)
|
|
113
|
-
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
114
|
-
value: function() {
|
|
115
|
-
return this;
|
|
116
|
-
}
|
|
117
|
-
}), g;
|
|
118
|
-
function verb(n) {
|
|
119
|
-
return function(v) {
|
|
120
|
-
return step([
|
|
121
|
-
n,
|
|
122
|
-
v
|
|
123
|
-
]);
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
function step(op) {
|
|
127
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
128
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
129
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
130
|
-
if (y = 0, t) op = [
|
|
131
|
-
op[0] & 2,
|
|
132
|
-
t.value
|
|
133
|
-
];
|
|
134
|
-
switch(op[0]){
|
|
135
|
-
case 0:
|
|
136
|
-
case 1:
|
|
137
|
-
t = op;
|
|
138
|
-
break;
|
|
139
|
-
case 4:
|
|
140
|
-
_.label++;
|
|
141
|
-
return {
|
|
142
|
-
value: op[1],
|
|
143
|
-
done: false
|
|
144
|
-
};
|
|
145
|
-
case 5:
|
|
146
|
-
_.label++;
|
|
147
|
-
y = op[1];
|
|
148
|
-
op = [
|
|
149
|
-
0
|
|
150
|
-
];
|
|
151
|
-
continue;
|
|
152
|
-
case 7:
|
|
153
|
-
op = _.ops.pop();
|
|
154
|
-
_.trys.pop();
|
|
155
|
-
continue;
|
|
156
|
-
default:
|
|
157
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
158
|
-
_ = 0;
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
162
|
-
_.label = op[1];
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
166
|
-
_.label = t[1];
|
|
167
|
-
t = op;
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
if (t && _.label < t[2]) {
|
|
171
|
-
_.label = t[2];
|
|
172
|
-
_.ops.push(op);
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
if (t[2]) _.ops.pop();
|
|
176
|
-
_.trys.pop();
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
op = body.call(thisArg, _);
|
|
180
|
-
} catch (e) {
|
|
181
|
-
op = [
|
|
182
|
-
6,
|
|
183
|
-
e
|
|
184
|
-
];
|
|
185
|
-
y = 0;
|
|
186
|
-
} finally{
|
|
187
|
-
f = t = 0;
|
|
188
|
-
}
|
|
189
|
-
if (op[0] & 5) throw op[1];
|
|
190
|
-
return {
|
|
191
|
-
value: op[0] ? op[1] : void 0,
|
|
192
|
-
done: true
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Vite plugin that transforms TypeScript and JavaScript files using SWC.
|
|
198
|
-
* It disables Vite's default esbuild transform to let SWC handle the compilation,
|
|
199
|
-
* resulting in significantly faster builds, especially for large codebases.
|
|
200
|
-
*
|
|
201
|
-
* @example
|
|
202
|
-
* ```ts
|
|
203
|
-
* // vite.config.ts
|
|
204
|
-
* import { defineConfig } from 'vite'
|
|
205
|
-
* import swc from '@o.z/vite-plugin-swc'
|
|
206
|
-
*
|
|
207
|
-
* export default defineConfig({
|
|
208
|
-
* plugins: [swc()]
|
|
209
|
-
* })
|
|
210
|
-
* ```
|
|
211
|
-
*
|
|
212
|
-
* @param options - Configuration options for the plugin and SWC.
|
|
213
|
-
* @returns A Vite plugin instance.
|
|
214
|
-
*/ var swc = function swc() {
|
|
215
|
-
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
216
|
-
// Default include/exclude patterns – now covering .ts, .tsx, .js, .jsx
|
|
217
|
-
var _options_include = options.include, include = _options_include === void 0 ? /\.(ts|tsx|js|jsx)$/ : _options_include, _options_exclude = options.exclude, exclude = _options_exclude === void 0 ? "node_modules" : _options_exclude, swcOptions = _object_without_properties(options, [
|
|
218
|
-
"include",
|
|
219
|
-
"exclude"
|
|
220
|
-
]);
|
|
221
|
-
var filter = createFilter(include, exclude);
|
|
222
|
-
return {
|
|
223
|
-
name: "vite-plugin-swc",
|
|
224
|
-
enforce: "pre",
|
|
225
|
-
config: function config() {
|
|
226
|
-
return {
|
|
227
|
-
esbuild: false
|
|
228
|
-
};
|
|
229
|
-
},
|
|
230
|
-
transform: function transform$1(code, id) {
|
|
231
|
-
return _async_to_generator(function() {
|
|
232
|
-
var _this_environment_config_css, sourceMaps, result, error;
|
|
233
|
-
return _ts_generator(this, function(_state) {
|
|
234
|
-
switch(_state.label){
|
|
235
|
-
case 0:
|
|
236
|
-
if (!filter(id)) return [
|
|
237
|
-
2,
|
|
238
|
-
null
|
|
239
|
-
];
|
|
240
|
-
_state.label = 1;
|
|
241
|
-
case 1:
|
|
242
|
-
_state.trys.push([
|
|
243
|
-
1,
|
|
244
|
-
3,
|
|
245
|
-
,
|
|
246
|
-
4
|
|
247
|
-
]);
|
|
248
|
-
// Determine if source maps should be generated based on Vite's config
|
|
249
|
-
// `this.environment.config` is available inside the transform hook
|
|
250
|
-
sourceMaps = this.environment.config.command === "build" ? !!this.environment.config.build.sourcemap : !!((_this_environment_config_css = this.environment.config.css) === null || _this_environment_config_css === void 0 ? void 0 : _this_environment_config_css.devSourcemap); // For dev, you might want to align with css sourcemaps or a dedicated flag
|
|
251
|
-
return [
|
|
252
|
-
4,
|
|
253
|
-
transform(code, _object_spread({
|
|
254
|
-
filename: id,
|
|
255
|
-
sourceFileName: id.split("?", 1)[0],
|
|
256
|
-
sourceMaps: sourceMaps
|
|
257
|
-
}, swcOptions))
|
|
258
|
-
];
|
|
259
|
-
case 2:
|
|
260
|
-
result = _state.sent();
|
|
261
|
-
// SWC returns { code, map } when sourceMaps are enabled, otherwise just { code }
|
|
262
|
-
return [
|
|
263
|
-
2,
|
|
264
|
-
{
|
|
265
|
-
code: result.code,
|
|
266
|
-
map: result.map
|
|
267
|
-
}
|
|
268
|
-
];
|
|
269
|
-
case 3:
|
|
270
|
-
error = _state.sent();
|
|
271
|
-
// Enhance error message with file information and re-throw as a plugin error
|
|
272
|
-
this.error("SWC transform failed in ".concat(id, ": ").concat((error === null || error === void 0 ? void 0 : error.message) || error));
|
|
273
|
-
return [
|
|
274
|
-
3,
|
|
275
|
-
4
|
|
276
|
-
];
|
|
277
|
-
case 4:
|
|
278
|
-
return [
|
|
279
|
-
2
|
|
280
|
-
];
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
}).call(this);
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
};
|
|
4
|
+
function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return}if(info.done){resolve(value);}else {Promise.resolve(value).then(_next,_throw);}}function _async_to_generator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);})}}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else {obj[key]=value;}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}));}ownKeys.forEach(function(key){_define_property(target,key,source[key]);});}return target}function _object_without_properties(source,excluded){if(source==null)return {};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return {};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}return target}function _ts_generator(thisArg,body){var f,y,t,_={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},g=Object.create((typeof Iterator==="function"?Iterator:Object).prototype),d=Object.defineProperty;return d(g,"next",{value:verb(0)}),d(g,"throw",{value:verb(1)}),d(g,"return",{value:verb(2)}),typeof Symbol==="function"&&d(g,Symbol.iterator,{value:function(){return this}}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(g&&(g=0,op[0]&&(_=0)),_)try{if(f=1,y&&(t=op[0]&2?y["return"]:op[0]?y["throw"]||((t=y["return"])&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return {value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(op[0]===6&&_.label<t[1]){_.label=t[1];t=op;break}if(t&&_.label<t[2]){_.label=t[2];_.ops.push(op);break}if(t[2])_.ops.pop();_.trys.pop();continue}op=body.call(thisArg,_);}catch(e){op=[6,e];y=0;}finally{f=t=0;}if(op[0]&5)throw op[1];return {value:op[0]?op[1]:void 0,done:true}}}var swc=function swc(){var options=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{swcrc:false,configFile:false,minify:true,jsc:{parser:{syntax:"typescript",decorators:true},transform:{decoratorMetadata:true,decoratorVersion:"2022-03"}}};var _options_include=options.include,include=_options_include===void 0?/\.(ts|tsx|js|jsx)$/:_options_include,_options_exclude=options.exclude,exclude=_options_exclude===void 0?"node_modules":_options_exclude,swcOptions=_object_without_properties(options,["include","exclude"]);var filter=createFilter(include,exclude);return {name:"vite-plugin-swc",enforce:"pre",config:function config(){return {esbuild:false}},transform:function transform$1(code,id){return _async_to_generator(function(){var _this_environment_config_css,sourceMaps,result,error;return _ts_generator(this,function(_state){switch(_state.label){case 0:if(!filter(id))return [2,null];_state.label=1;case 1:_state.trys.push([1,3,,4]);sourceMaps=this.environment.config.command==="build"?!!this.environment.config.build.sourcemap:!!((_this_environment_config_css=this.environment.config.css)===null||_this_environment_config_css===void 0?void 0:_this_environment_config_css.devSourcemap);return [4,transform(code,_object_spread({filename:id,sourceFileName:id.split("?",1)[0],sourceMaps:sourceMaps},swcOptions))];case 2:result=_state.sent();return [2,{code:result.code,map:result.map}];case 3:error=_state.sent();this.error("SWC transform failed in ".concat(id,": ").concat((error===null||error===void 0?void 0:error.message)||error));return [3,4];case 4:return [2]}})}).call(this)}}};
|
|
287
5
|
|
|
288
6
|
export { swc as default, swc };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@o.z/vite-plugin-swc",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "A high-performance Vite plugin that transforms TypeScript and JavaScript files using SWC for lightning-fast builds",
|
|
5
5
|
"homepage": "https://github.com/z-npm/vite-plugin-swc#readme",
|
|
6
6
|
"docs": "https://github.com/z-npm/vite-plugin-swc#readme",
|