如何使用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的地方。
- Android Studio 2.2无法find所有kotlin文件的引用
- 如何用gradle-script-kotlin配置spring-boot重新打包
- Gradle构建中未解决的Kotlin扩展函数的引用
- 无法使Coverity Scan工作(Windows和Travis上的Java / Kotlin / Gradle 3.3)
- 在intellij中运行并执行jar时的微妙差异
- 如何覆盖gradle kotlin-dsl中的任务
- 用Gradle和Kotlin构建一个可执行的jar
- Kotlin 1.0.0-rc-1036注释处理问题
- 未解决的参考:kotlinx – Kotlin 1-0-0-RC-1036