vatts 1.2.0-test.1 → 1.2.0-test.2
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/dist/loaders.d.ts +1 -0
- package/dist/loaders.js +55 -68
- package/package.json +1 -1
package/dist/loaders.d.ts
CHANGED
package/dist/loaders.js
CHANGED
|
@@ -13,15 +13,11 @@ let esbuild;
|
|
|
13
13
|
try {
|
|
14
14
|
sfcCompiler = require('vue/compiler-sfc');
|
|
15
15
|
}
|
|
16
|
-
catch (e) {
|
|
17
|
-
// Vue não instalado ou não encontrado
|
|
18
|
-
}
|
|
16
|
+
catch (e) { }
|
|
19
17
|
try {
|
|
20
18
|
esbuild = require('esbuild');
|
|
21
19
|
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
// Esbuild não instalado
|
|
24
|
-
}
|
|
20
|
+
catch (e) { }
|
|
25
21
|
const { loadTsConfigPaths, resolveTsConfigAlias, resolveWithNodeStyleExtensions } = require('./tsconfigPaths');
|
|
26
22
|
/**
|
|
27
23
|
* Carrega e processa o tsconfig.json para obter os aliases
|
|
@@ -76,12 +72,10 @@ function registerLoaders(options = {}) {
|
|
|
76
72
|
}
|
|
77
73
|
// --- File Handlers ---
|
|
78
74
|
require.extensions['.md'] = function (module, filename) {
|
|
79
|
-
|
|
80
|
-
module.exports = content;
|
|
75
|
+
module.exports = fs.readFileSync(filename, 'utf8');
|
|
81
76
|
};
|
|
82
77
|
require.extensions['.txt'] = function (module, filename) {
|
|
83
|
-
|
|
84
|
-
module.exports = content;
|
|
78
|
+
module.exports = fs.readFileSync(filename, 'utf8');
|
|
85
79
|
};
|
|
86
80
|
const styleExtensions = ['.css', '.scss', '.sass', '.less'];
|
|
87
81
|
styleExtensions.forEach(ext => {
|
|
@@ -101,7 +95,6 @@ function registerLoaders(options = {}) {
|
|
|
101
95
|
throw new Error('Para carregar arquivos .vue no servidor, você precisa instalar "vue" e "esbuild".');
|
|
102
96
|
}
|
|
103
97
|
const source = fs.readFileSync(filename, 'utf8');
|
|
104
|
-
// Variável para armazenar o código final para fins de debug
|
|
105
98
|
let finalEsm = '';
|
|
106
99
|
try {
|
|
107
100
|
// 1. Parse do SFC
|
|
@@ -112,72 +105,66 @@ function registerLoaders(options = {}) {
|
|
|
112
105
|
if (errors.length > 0) {
|
|
113
106
|
console.error(`Erro ao parsear ${filename}:`, errors);
|
|
114
107
|
}
|
|
115
|
-
// 2. Compilação do Script
|
|
116
|
-
|
|
117
|
-
let scriptContent = 'const _sfc_main = {};';
|
|
108
|
+
// 2. Compilação do Script
|
|
109
|
+
let scriptContent = '';
|
|
118
110
|
let bindings = undefined;
|
|
119
111
|
if (descriptor.script || descriptor.scriptSetup) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
// mantemos o conteúdo original e ADICIONAMOS a definição do _sfc_main manualmente.
|
|
134
|
-
scriptContent = compiledScript.content + '\nconst _sfc_main = {};';
|
|
135
|
-
}
|
|
136
|
-
bindings = compiledScript.bindings;
|
|
112
|
+
const compiledScript = sfcCompiler.compileScript(descriptor, {
|
|
113
|
+
id: filename,
|
|
114
|
+
isProd: false,
|
|
115
|
+
inlineTemplate: false
|
|
116
|
+
});
|
|
117
|
+
scriptContent = compiledScript.content;
|
|
118
|
+
bindings = compiledScript.bindings;
|
|
119
|
+
const hasSfcMain = /\bconst\s+_sfc_main\b/.test(scriptContent) ||
|
|
120
|
+
/\blet\s+_sfc_main\b/.test(scriptContent) ||
|
|
121
|
+
/\bvar\s+_sfc_main\b/.test(scriptContent);
|
|
122
|
+
// Caso tenha "export default"
|
|
123
|
+
if (/export\s+default/.test(scriptContent)) {
|
|
124
|
+
scriptContent = scriptContent.replace(/export\s+default/, 'const _sfc_main =');
|
|
137
125
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
126
|
+
// Caso NÃO tenha export default e NÃO tenha _sfc_main
|
|
127
|
+
else if (!hasSfcMain) {
|
|
128
|
+
scriptContent += '\nconst _sfc_main = {};';
|
|
141
129
|
}
|
|
142
130
|
}
|
|
131
|
+
else {
|
|
132
|
+
// Sem script nenhum
|
|
133
|
+
scriptContent = 'const _sfc_main = {};';
|
|
134
|
+
}
|
|
143
135
|
// 3. Compilação do Template para SSR
|
|
144
136
|
let templateContent = '';
|
|
145
137
|
if (descriptor.template) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
templateContent = templateResult.code;
|
|
158
|
-
}
|
|
159
|
-
catch (e) {
|
|
160
|
-
console.error(`Erro ao compilar template Vue em ${filename}:`, e.message);
|
|
161
|
-
}
|
|
138
|
+
const templateResult = sfcCompiler.compileTemplate({
|
|
139
|
+
source: descriptor.template.content,
|
|
140
|
+
filename,
|
|
141
|
+
id: filename,
|
|
142
|
+
ssr: true,
|
|
143
|
+
compilerOptions: {
|
|
144
|
+
bindingMetadata: bindings
|
|
145
|
+
},
|
|
146
|
+
ssrCssVars: descriptor.cssVars || []
|
|
147
|
+
});
|
|
148
|
+
templateContent = templateResult.code;
|
|
162
149
|
}
|
|
163
|
-
// 4. Montagem do Código Final
|
|
150
|
+
// 4. Montagem do Código Final
|
|
164
151
|
finalEsm = `
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
// 5. Transformação
|
|
152
|
+
${scriptContent}
|
|
153
|
+
${templateContent}
|
|
154
|
+
|
|
155
|
+
// Anexa render ao componente
|
|
156
|
+
if (typeof _sfc_main !== 'undefined') {
|
|
157
|
+
if (typeof ssrRender !== 'undefined') {
|
|
158
|
+
_sfc_main.ssrRender = ssrRender;
|
|
159
|
+
}
|
|
160
|
+
if (typeof render !== 'undefined') {
|
|
161
|
+
_sfc_main.render = render;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export default _sfc_main;
|
|
166
|
+
`;
|
|
167
|
+
// 5. Transformação para CJS
|
|
181
168
|
const result = esbuild.transformSync(finalEsm, {
|
|
182
169
|
loader: 'ts',
|
|
183
170
|
format: 'cjs',
|
|
@@ -193,7 +180,7 @@ function registerLoaders(options = {}) {
|
|
|
193
180
|
console.error(`Erro original: ${err.message}`);
|
|
194
181
|
if (finalEsm) {
|
|
195
182
|
console.error(`\n[DEBUG] Código gerado (Snippet):`);
|
|
196
|
-
console.error(finalEsm.split('\n').slice(0,
|
|
183
|
+
console.error(finalEsm.split('\n').slice(0, 40).join('\n') + '\n...');
|
|
197
184
|
}
|
|
198
185
|
console.error(`--------------------------\n`);
|
|
199
186
|
throw err;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vatts",
|
|
3
|
-
"version": "1.2.0-test.
|
|
3
|
+
"version": "1.2.0-test.2",
|
|
4
4
|
"description": "Vatts.js is a high-level framework for building web applications with ease and speed. It provides a robust set of tools and features to streamline development and enhance productivity.",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "itsmuzin",
|