gpt4 book ai didi

gradle - 如何使用kotlin-frontend-plugin设置package.json配置

转载 作者:行者123 更新时间:2023-12-02 13:00:24 25 4
gpt4 key购买 nike

我希望以指向Kotlin生成的JavaScript文件的方式配置自动生成的package.json。这是我当前的gradle配置:

apply plugin: 'kotlin-platform-js'
apply from: "$project.rootDir/gradle/deploy.gradle"


dependencies {
expectedBy project(":")

// Compile/implementation dependencies
implementation "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
}

apply plugin: 'org.jetbrains.kotlin.frontend'

compileKotlin2Js {
kotlinOptions.metaInfo = true
kotlinOptions.sourceMap = true
kotlinOptions.moduleKind = 'commonjs'
}

kotlinFrontend {
sourceMaps = true

npm {
dependency("kotlin")
replaceVersion("kotlin-js-library", "1.1.0")
}

define "PRODUCTION", true

webpackBundle {
bundleName = "${project.name}"
sourceMapEnabled = true
}
}

这将输出位于$ project.builDir.path / classes / nain中的myProject.js文件,这是我希望在生成的package.json文件中得到反射(reflect)的文件。但是输出的package.json文件(位于项目的build目录中)如下所示:
{
"name": "myProject",
"version": "1.2.0-10-SNAPSHOT",
"description": "simple description",
"main": "myProject",
"dependencies": {
"kotlin": "*"
},
"devDependencies": {
"webpack": "*",
"webpack-dev-server": "*",
"source-map-loader": "*",
"karma": "*",
"qunitjs": "1.23.1",
"karma-qunit": "*",
"karma-sourcemap-loader": "*",
"karma-phantomjs-launcher": "*",
"phantomjs-prebuilt": "*",
"karma-webpack": "*"
}
}

问题是,package.json中的“main”属性未指向位于classes / main / myProject.js中的 bundle 文件。我尝试浏览文档以找到如何将main属性设置为特定目录和js文件,但找不到它。我只能通过在gradle文件的webpackBundle部分中设置bundleName属性来更改名称。我在这里先向您的帮助表示感谢!

最佳答案

因此,我找到了一种解决方法,可以使用gradle将其发布到npm。我在代码中添加了以下内容:

apply plugin: "com.moowork.node"

//Must copy the output javascript file
//to the location that the package.json expects it to be
//This is semi-workaround since I have not found a way to
//configure the outputted package.json file
task copyJSFile(type: Copy){

from "$project.buildDir.path/classes/main/"
into "${project.buildDir}"
include "*.js"
}

//We publish our project to npm
task npmPublish(dependsOn: copyJSFile, type: NpmTask) {
description = "publishes the project to npm"
workingDir = file("${project.buildDir}")
args = ['publish']
}

这样做是将输出的JavaScript生成的文件复制到调用npmPublish gradle任务时配置package.json的位置。

关于gradle - 如何使用kotlin-frontend-plugin设置package.json配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47926626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com