Skip to content

Commit

Permalink
fix: 修复 vitepress 打包时 vite寻找vue目录错误的问题
Browse files Browse the repository at this point in the history
修复 vitepress 打包时 vite寻找vue目录错误的问题
  • Loading branch information
hewx815 committed Apr 23, 2023
1 parent bd99ed6 commit d99acf2
Show file tree
Hide file tree
Showing 9 changed files with 4,563 additions and 430 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
node_modules/

for-vue2/dist
for-vue3/dist

dist/doc/*
dist/npm/*

cli/storage/index.json
.vitepress/cache
7 changes: 7 additions & 0 deletions cli/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path';
import { fileURLToPath } from 'url';
import { spawn } from 'child_process';
import fs from 'fs';
import {
choiceDevConfig,
choiceDevFolder,
Expand Down Expand Up @@ -76,5 +77,11 @@ export const startBuild = async () => {
delDir(vue3Package.destDir);
copyPackages(vue2Package.srcDir, vue2Package.destDir);
copyPackages(vue3Package.srcDir, vue3Package.destDir);
const vue2PackagePath = path.resolve(CurrentPath, '../for-vue2/node_modules/vue');
const newVue2PackagePath = path.resolve(CurrentPath, '../for-vue2/node_modules/vue_old');
if (fs.existsSync(vue2PackagePath)) {
fs.renameSync(vue2PackagePath, newVue2PackagePath);
}
spawn('yarn vitepress build', { shell: true, stdio: 'inherit' });
fs.renameSync(newVue2PackagePath, newVue2PackagePath);
};
2 changes: 1 addition & 1 deletion cli/storage/index.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"USER_LAST_MODE":{"updataTime":"Thu Apr 20 2023 23:27:10 GMT+0800 (中国标准时间)","data":{"devFolder":"for-vue3","script":"dev:h5"}}}
{"USER_LAST_MODE":{"updataTime":"Sun Apr 23 2023 21:34:29 GMT+0800 (中国标准时间)","data":{"devFolder":"for-vue2","script":"build:h5"}}}
1 change: 1 addition & 0 deletions cli/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import inquirer from 'inquirer';
import fs from 'fs';
import path from 'path';
Expand Down
77 changes: 38 additions & 39 deletions for-vue2/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
const webpack = require('webpack')
const plugins = []
const webpack = require('webpack');

const plugins = [];

if (process.env.UNI_OPT_TREESHAKINGNG) {
plugins.push(require('@dcloudio/vue-cli-plugin-uni-optimize/packages/babel-plugin-uni-api/index.js'))
plugins.push(require('@dcloudio/vue-cli-plugin-uni-optimize/packages/babel-plugin-uni-api/index.js'));
}

if (
(
process.env.UNI_PLATFORM === 'app-plus' &&
process.env.UNI_USING_V8
) ||
(
process.env.UNI_PLATFORM === 'h5' &&
process.env.UNI_H5_BROWSER === 'builtin'
process.env.UNI_PLATFORM === 'app-plus'
&& process.env.UNI_USING_V8
)
|| (
process.env.UNI_PLATFORM === 'h5'
&& process.env.UNI_H5_BROWSER === 'builtin'
)
) {
const path = require('path')
const path = require('path');

const isWin = /^win/.test(process.platform)
const isWin = /^win/.test(process.platform);

const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
const normalizePath = (path) => (isWin ? path.replace(/\\/g, '/') : path);

const input = normalizePath(process.env.UNI_INPUT_DIR)
const input = normalizePath(process.env.UNI_INPUT_DIR);
try {
plugins.push([
require('@dcloudio/vue-cli-plugin-hbuilderx/packages/babel-plugin-console'),
{
file (file) {
file = normalizePath(file)
file(file) {
file = normalizePath(file);
if (file.indexOf(input) === 0) {
return path.relative(input, file)
return path.relative(input, file);
}
return false
}
}
])
return false;
},
},
]);
} catch (e) { }
}

process.UNI_LIBRARIES = process.UNI_LIBRARIES || ['@dcloudio/uni-ui']
process.UNI_LIBRARIES.forEach(libraryName => {
process.UNI_LIBRARIES = process.UNI_LIBRARIES || ['@dcloudio/uni-ui'];
process.UNI_LIBRARIES.forEach((libraryName) => {
plugins.push([
'import',
{
'libraryName': libraryName,
'customName': (name) => {
return `${libraryName}/lib/${name}/${name}`
}
}
])
})
libraryName,
customName: (name) => `${libraryName}/lib/${name}/${name}`,
},
]);
});

if (process.env.UNI_PLATFORM !== 'h5') {
plugins.push('@babel/plugin-transform-runtime')
plugins.push('@babel/plugin-transform-runtime');
}

const config = {
Expand All @@ -61,21 +60,21 @@ const config = {
'@vue/app',
{
modules: webpack.version[0] > 4 ? 'auto' : 'commonjs',
useBuiltIns: process.env.UNI_PLATFORM === 'h5' ? 'usage' : 'entry'
}
]
useBuiltIns: process.env.UNI_PLATFORM === 'h5' ? 'usage' : 'entry',
},
],
],
plugins
}
plugins,
};

const UNI_H5_TEST = '**/@dcloudio/uni-h5/dist/index.umd.min.js'
const UNI_H5_TEST = '**/@dcloudio/uni-h5/dist/index.umd.min.js';
if (process.env.NODE_ENV === 'production') {
config.overrides = [{
test: UNI_H5_TEST,
compact: true,
}]
}];
} else {
config.ignore = [UNI_H5_TEST]
config.ignore = [UNI_H5_TEST];
}

module.exports = config
module.exports = config;
5 changes: 3 additions & 2 deletions for-vue2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"@vue/shared": "^3.0.0",
"core-js": "^3.8.3",
"flyio": "^0.6.2",
"vue": ">= 2.6.14 < 2.7",
"vue": "2.6.14",
"vue-server-renderer": "^2.7.14",
"vuex": "^3.2.0"
},
"devDependencies": {
Expand Down Expand Up @@ -104,4 +105,4 @@
"uni-app": {
"scripts": {}
}
}
}

0 comments on commit d99acf2

Please sign in to comment.