mm_statics 1.6.9 → 1.7.0

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/vue_compiler.js +23 -23
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_statics",
3
- "version": "1.6.9",
3
+ "version": "1.7.0",
4
4
  "description": "这是超级美眉statics函数模块,用于web服务端statics缓存",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/vue_compiler.js CHANGED
@@ -77,10 +77,6 @@ class VueSFCCompiler {
77
77
  // 检查是否已经使用了 defineComponent
78
78
  const hasDefineComponent = result.content.includes('defineComponent');
79
79
 
80
- // 检查是否已经导入了 defineComponent
81
- const hasDefineComponentImport = result.content.includes('import { defineComponent }') ||
82
- result.content.includes('import defineComponent');
83
-
84
80
  // 移除 export default,改为赋值给 __script 变量
85
81
  let scriptContent = result.content || '';
86
82
  if (scriptContent.includes('export default')) {
@@ -141,28 +137,30 @@ class VueSFCCompiler {
141
137
  let styleCode = '';
142
138
  for (let i = 0; i < descriptor.styles.length; i++) {
143
139
  const style = descriptor.styles[i];
144
- const result = await compileStyleAsync({
145
- source: style.content,
146
- filename,
147
- id: style.scoped ? `data-v-${descriptor.id}` : undefined,
148
- scoped: style.scoped,
149
- isProd: this.options.isProduction
150
- });
151
-
152
- if (result.errors.length) {
153
- console.warn(`Style compile warning: ${result.errors[0]}`);
154
- continue;
155
- }
156
-
157
- // 对于 scoped 样式,添加 scopeId 到组件
158
- if (style.scoped) {
140
+
141
+ // 对于 global 样式,直接使用原始内容,不进行 scoped 编译
142
+ if (!style.scoped) {
159
143
  styleCode += `
160
- // Scoped styles for ${descriptor.id}
161
- const __style_${i} = \`${result.code.replace(/`/g, '\\`')}\`;
144
+ // Global styles
145
+ const __style_${i} = \`${style.content.replace(/`/g, '\\`')}\`;
162
146
  `;
163
147
  } else {
148
+ // 对于 scoped 样式,使用 Vue 的编译逻辑
149
+ const result = await compileStyleAsync({
150
+ source: style.content,
151
+ filename,
152
+ id: `data-v-${descriptor.id}`,
153
+ scoped: true,
154
+ isProd: this.options.isProduction
155
+ });
156
+
157
+ if (result.errors.length) {
158
+ console.warn(`Style compile warning: ${result.errors[0]}`);
159
+ continue;
160
+ }
161
+
164
162
  styleCode += `
165
- // Global styles
163
+ // Scoped styles for ${descriptor.id}
166
164
  const __style_${i} = \`${result.code.replace(/`/g, '\\`')}\`;
167
165
  `;
168
166
  }
@@ -223,7 +221,9 @@ function injectStyles() {
223
221
  // 创建 style 元素
224
222
  const styleEl = document.createElement('style');
225
223
  styleEl.id = styleId;
226
- styleEl.textContent = __style_0;
224
+
225
+ // 根据是否有 scoped 样式来决定注入的样式内容
226
+ ${hasScopedStyle ? 'styleEl.textContent = __style_0;' : 'styleEl.textContent = __style_0;'}
227
227
 
228
228
  // 插入到 head
229
229
  document.head.appendChild(styleEl);