Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manifest.json 中支付宝端增加 component2 选项 #1164

Closed
xlfsummer opened this issue Dec 23, 2019 · 2 comments
Closed

manifest.json 中支付宝端增加 component2 选项 #1164

xlfsummer opened this issue Dec 23, 2019 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@xlfsummer
Copy link

新功能描述
在 manifest.json > mp-alipay 下增加一个 component2 属性配置,类型为 boolean
当有此字段时,编译输出的文件(dist/dev/mp-alipay 或 dist/build/mp-alipay) 下增加一个 mini.project.json 文件, 文件内容为:

{
  "component2":  true /**(读取 manifest.json > mp-alipay > component2 中配置的值) */
}

支付宝小程序开发工具会读取此文件的值作为 component2 选项

现状及问题
生成输出后需要手动打开工具勾选 component2 选项

@xlfsummer xlfsummer added the enhancement New feature or request label Dec 23, 2019
@exvu
Copy link

exvu commented Dec 25, 2019

您可以使用vue.config.js

manifest.json

{
  "component2":  true /**(读取 manifest.json > mp-alipay > component2 中配置的值) */
}

vue.config.js

const path = require('path')
const fs = require('fs')
const Json5 = require('json5')
/**
 * 自己实现支付宝配置
 */
function MyPlugin(options) {
	this.options = options;
}
MyPlugin.prototype.apply = function(compiler) {

	// console.log('开始执行插件')

	compiler.plugin('compile', function() {})

	compiler.plugin('compilation', function(compilation) {
		// console.log('编译器开始一个新的编译任务...-----')
		compilation.plugin('optimize', function() {
			// console.log('编译器开始优化文件...')
		})
	})
	compiler.plugin('done', function() {

		if (process.env.UNI_PLATFORM == 'mp-alipay') {

			const fscontent = Json5.parse(fs.readFileSync(path.join(__dirname, 'manifest.json')))
			const filePath = path.join(__dirname + '/unpackage/', 'dist', process.env.NODE_ENV === 'production' ? 'build' :
				'dev', process.env.UNI_PLATFORM, '/', 'mini.project.json');
			fs.writeFileSync(filePath, JSON.stringify(fscontent['mp-alipay']))
			console.log('生成支付宝小程序项目配置文件成功')
		}
	})

};
module.exports = {
	configureWebpack: {
		plugins: [
			new MyPlugin()
		]

	}

}

@Wangyaqi
Copy link
Contributor

2.5.0已支持

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants