mm_statics 1.6.9 → 1.7.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/index.js +4 -2
- package/package.json +1 -1
- package/vue_compiler.js +23 -23
package/index.js
CHANGED
|
@@ -35,6 +35,8 @@ class Static {
|
|
|
35
35
|
gzip: false,
|
|
36
36
|
// 静态文件根目录
|
|
37
37
|
root: './static',
|
|
38
|
+
// 路由路径
|
|
39
|
+
path: '/',
|
|
38
40
|
// 是否编译Vue文件为JS
|
|
39
41
|
compile_vue: true,
|
|
40
42
|
// 是否编译Markdown文件为HTML
|
|
@@ -42,7 +44,7 @@ class Static {
|
|
|
42
44
|
// 编译Markdown文件时,是否添加引入css和js文件
|
|
43
45
|
markdown_link: ['/css/common.css', '/css/markdown.css', '/js/markdown.js'],
|
|
44
46
|
// 需要转换的静态文件路径前缀
|
|
45
|
-
|
|
47
|
+
src_path: '/src',
|
|
46
48
|
// 需要转换的静态文件扩展名
|
|
47
49
|
files: ['.js', '.vue', '.html'],
|
|
48
50
|
// 是否转换ES6模块为AMD模块
|
|
@@ -614,7 +616,7 @@ Static.prototype._handleCache = async function (url, ctx) {
|
|
|
614
616
|
Static.prototype._handleFileCompile = async function (path) {
|
|
615
617
|
if (this.config.compile_md && path.extname() === '.md') {
|
|
616
618
|
return await this._runMarkdown(path);
|
|
617
|
-
} else if (!path.startsWith(this.config.
|
|
619
|
+
} else if (!path.startsWith(this.config.src_path)) return null;
|
|
618
620
|
|
|
619
621
|
let file_type = this._getType(path);
|
|
620
622
|
let { compile_vue, convert_amd } = this.config;
|
package/package.json
CHANGED
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
//
|
|
161
|
-
const __style_${i} = \`${
|
|
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
|
-
//
|
|
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
|
-
|
|
224
|
+
|
|
225
|
+
// 根据是否有 scoped 样式来决定注入的样式内容
|
|
226
|
+
${hasScopedStyle ? 'styleEl.textContent = __style_0;' : 'styleEl.textContent = __style_0;'}
|
|
227
227
|
|
|
228
228
|
// 插入到 head
|
|
229
229
|
document.head.appendChild(styleEl);
|