提交 8f8aa2af 编写于 作者: Q qiang

feat: support pnpm :question/133516

上级 ae6ea342
......@@ -85,8 +85,7 @@ function getH5Options (manifestJson) {
}
/* eslint-disable no-mixed-operators */
h5.template = h5.template && path.resolve(process.env.UNI_INPUT_DIR, h5.template) || path.resolve(__dirname,
'../../../../public/index.html')
h5.template = h5.template && path.resolve(process.env.UNI_INPUT_DIR, h5.template) || path.resolve(require('./util').getCLIContext(), 'public/index.html')
h5.devServer = h5.devServer || {}
......@@ -103,4 +102,4 @@ module.exports = {
parseManifestJson,
getNetworkTimeout,
getH5Options
}
}
......@@ -14,6 +14,24 @@ try {
const isInHBuilderX = !!aboutPkg
const isInHBuilderXAlpha = !!(isInHBuilderX && aboutPkg.alpha)
function getCLIContext () {
var context = path.resolve(__dirname, '../../../../')
// const isInHBuilderX = fs.existsSync(path.resolve(context, 'bin/uniapp-cli.js'))
if (isInHBuilderX) {
return context
}
const pnpmFind = __dirname.match(/.+?[\/\\].pnpm[\/\\]/)
if (pnpmFind) {
const pnpm = pnpmFind[0]
context = path.resolve(pnpm, '../../')
}
const isInCLI = fs.existsSync(path.resolve(context, './src'))
if (isInCLI) {
return context
}
return process.cwd()
}
function removeExt (str, ext) {
if (ext) {
const reg = new RegExp(ext.replace(/\./, '\\.') + '$')
......@@ -105,6 +123,7 @@ const _hasOwnProperty = Object.prototype.hasOwnProperty
module.exports = {
isInHBuilderX,
isInHBuilderXAlpha,
getCLIContext,
normalizeNodeModules,
md5,
hasOwn (obj, key) {
......
......@@ -2,7 +2,7 @@ const fs = require('fs')
const path = require('path')
const uniI18n = require('@dcloudio/uni-cli-i18n')
process.env.UNI_CLI_CONTEXT = path.resolve(__dirname, '../../../')
process.env.UNI_CLI_CONTEXT = require('@dcloudio/uni-cli-shared/lib/util').getCLIContext()
process.env.UNI_HBUILDERX_PLUGINS = process.env.UNI_HBUILDERX_PLUGINS || path.resolve(__dirname, '../../../../')
......
......@@ -15,7 +15,7 @@ function resolve (dir) {
}
function resolveModule (dir) {
return path.resolve(__dirname, '../../..', dir)
return path.resolve(process.env.UNI_CLI_CONTEXT, './node_modules', dir)
}
module.exports = function configureWebpack (platformOptions, manifestPlatformOptions, vueOptions, api) {
......@@ -184,8 +184,9 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
platformWebpackConfig = platformWebpackConfig(webpackConfig, vueOptions, api)
}
// 移除 node_modules 目录,避免受路径上的 node_modules 影响
webpackConfig.resolve.modules = webpackConfig.resolve.modules.filter(module => module !==
'node_modules')
if (require('@dcloudio/uni-cli-shared/lib/util').isInHBuilderX) {
webpackConfig.resolve.modules = webpackConfig.resolve.modules.filter(module => module !== 'node_modules')
}
const plugins = []
......@@ -298,6 +299,17 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
}
} catch (e) {}
const resolveLoaderAlias = {}
const modules = ['@vue/cli-plugin-babel', '@vue/cli-service']
modules.forEach(m => {
const { dependencies } = require(`${m}/package.json`)
Object.keys(dependencies).forEach(key => {
if (/-loader$/.test(key)) {
resolveLoaderAlias[key] = require.resolve(key)
}
})
})
return merge({
devtool: false,
resolve: {
......@@ -325,6 +337,9 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
noParse: /^(vue|vue-router|vuex|vuex-router-sync)$/,
rules
},
resolveLoader: {
alias: resolveLoaderAlias
},
plugins,
performance: {
assetFilter (assetFilename) {
......@@ -334,4 +349,4 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
watchOptions: require('./util').getWatchOptions()
}, platformWebpackConfig)
}
}
}
......@@ -107,11 +107,13 @@ if (process.env.UNI_CLOUD_SPACES) {
}
// 初始化环境变量
const defaultOutputDir = '../../../../dist/' +
process.env.UNI_CLI_CONTEXT = require('@dcloudio/uni-cli-shared/lib/util').getCLIContext()
const defaultOutputDir = './dist/' +
(process.env.NODE_ENV === 'production' ? 'build' : 'dev') + '/' +
(process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM)
process.env.UNI_OUTPUT_DEFAULT_DIR = path.resolve(__dirname, defaultOutputDir)
process.env.UNI_OUTPUT_DEFAULT_DIR = path.resolve(process.env.UNI_CLI_CONTEXT, defaultOutputDir)
if (process.env.UNI_OUTPUT_DIR && process.env.UNI_OUTPUT_DIR.indexOf('./') === 0) {
process.env.UNI_OUTPUT_DIR = path.resolve(process.cwd(), process.env.UNI_OUTPUT_DIR)
}
......@@ -124,8 +126,6 @@ if (process.env.UNI_PLATFORM === 'app-plus') {
process.env.UNI_OUTPUT_TMP_DIR = path.resolve(process.env.UNI_OUTPUT_DIR, '../.tmp/app-plus')
}
process.env.UNI_CLI_CONTEXT = path.resolve(__dirname, '../../../../')
process.UNI_LIBRARIES = process.UNI_LIBRARIES || ['@dcloudio/uni-ui']
if (process.env.NODE_ENV === 'production') { // 发行模式,不启用 cache
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册