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

我想要自动生成的package.json被配置为指向Kotlin生成的JavaScript文件。 这是我目前的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文件中反映的。 但是输出的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文件。 我试图通过文档查找如何设置主要属性到特定的目录和js文件,但无法find它。 我只能通过在gradle文件的webpackBundle部分中设置bundleName属性来更改名称。 我在这里先向您的帮助表示感谢!

所以我find了一个可以使用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的地方。