| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #!/usr/bin/env node
- const fs = require('fs');
- const path = require('path');
- function findRemoveScopedFiles() {
- const files = [];
- const localPath = path.join(__dirname, 'node_modules', '@dcloudio',
- 'vue-cli-plugin-uni', 'packages', '@vue', 'component-compiler-utils',
- 'dist', 'stylePlugins', 'remove-scoped.js');
- if (fs.existsSync(localPath)) files.push(localPath);
- return files;
- }
- function patchFile(filePath) {
- let content = fs.readFileSync(filePath, 'utf8');
- if (content.includes("selector.first.spaces.before = '';")) {
- content = content.replace(
- /selector\.first\.spaces\.before = '';/,
- "if (selector.first) { selector.first.spaces.before = ''; }"
- );
- fs.writeFileSync(filePath, content, 'utf8');
- console.log(` ✅ ${filePath}`);
- return true;
- } else if (content.includes("if (selector.first) { selector.first.spaces.before = ''; }")) {
- console.log(` ⏭️ ${filePath} (already patched)`);
- return true;
- }
- return false;
- }
- function patchTemplateLoader(filePath) {
- let content = fs.readFileSync(filePath, 'utf8');
- if (content.includes("export { render, staticRenderFns }") && !content.includes("recyclableRender")) {
- return true;
- }
- const oldExport = /export \{ render, staticRenderFns, recyclableRender, components \}/;
- if (oldExport.test(content)) {
- content = content.replace(oldExport, "export { render, staticRenderFns }");
- fs.writeFileSync(filePath, content, 'utf8');
- console.log(` ✅ ${filePath}`);
- return true;
- }
- return false;
- }
- const files = findRemoveScopedFiles();
- if (files.length === 0) {
- console.log('remove-scoped.js not found, skipping');
- } else {
- let patched = 0;
- for (const f of files) { if (patchFile(f)) patched++; }
- console.log(`Done: ${patched}/${files.length} patched`);
- }
- const templateLoaderPath = path.join(__dirname, 'node_modules', '@dcloudio',
- 'vue-cli-plugin-uni', 'packages', 'vue-loader', 'lib', 'loaders', 'templateLoader.js');
- if (fs.existsSync(templateLoaderPath)) {
- patchTemplateLoader(templateLoaderPath);
- }
|