scalajs-bundler包含jQuery插件

时间:2018-05-26 16:00:58

标签: javascript jquery webpack scala.js scalajs-bundler

我将jQuery modal dialog plugin jQuery facade一起使用。它一直有效,直到我决定使用scala-bundlerjsDependencies更改为Webpack。 Webpack生成的包自定义Javascript没有包含模态对话框脚本。这可能是这个模态对话框库不兼容Webpack但我不能说,因为我不熟悉Webpack。如何使我的项目生成最终包以包含模态对话框?请指教。感谢

查看模态对话框脚本,我想我只需要在加载时执行模态对话框脚本,它会将自身附加到$。我创建的jQuery外观应该保持不变。不幸的是,我不知道如何使用Scala.js。

我已将build.sbt

的一部分包括在内
  lazy val server = (project in file("server")).settings(commonSettings).settings(
  scalaJSProjects := Seq(client),
  pipelineStages in Assets := Seq(scalaJSPipeline),
  compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value,
  libraryDependencies ++= Seq(
    "com.typesafe.akka" %% "akka-http" % "10.1.1",
    "com.typesafe.akka" %% "akka-stream" % "2.5.11",
    "com.vmunier" %% "scalajs-scripts" % "1.1.2"
  ),
  WebKeys.packagePrefix in Assets := "public/",
  managedClasspath in Runtime += (packageBin in Assets).value)
  .enablePlugins(SbtWeb, JavaAppPackaging, WebScalaJSBundlerPlugin)
  .dependsOn(sharedJvm)

lazy val client = (project in file("client")).settings(commonSettings).settings(
  libraryDependencies ++= Seq(
    "org.scala-js" %%% "scalajs-dom" % "0.9.5",
    "org.querki" %%% "jquery-facade" % "1.2",
    "org.querki" %%% "querki-jsext" % "0.8",
    "com.lihaoyi" %%% "upickle" % "0.6.5",
    "com.lihaoyi" %%% "utest" % "0.6.3" % "test"),
  scalaJSUseMainModuleInitializer := true,
  skip in packageJSDependencies := false,
  npmDevDependencies in Compile ++= Seq(
    "webpack-merge" -> "4.1.2",
    "imports-loader" -> "0.8.0",
    "expose-loader" -> "0.7.5"),     
  npmDependencies in Compile ++= Seq(
    "jquery" -> "2.2.1",
    "jquery-modal" -> "0.9.1"))
  .enablePlugins(ScalaJSBundlerPlugin, ScalaJSWeb)
  .dependsOn(sharedJs)

更新1

在我使用自定义$公开jQuery后,jQuery插件设法看到webpack.config.js,如下所示。但是,我必须使用<script ...>在HTML页面中包含该插件。如何在ScalaJS中包含和执行插件,并避免HTML页面中的<script>标记?

const webpack = require('webpack')

module.exports = {
module: {
    rules: [
        // any other rules
        {
            // Exposes jQuery for use outside Webpack build
            test: require.resolve('jquery'),
            use: [{
                loader: 'expose-loader',
                options: 'jQuery'
            },{
                loader: 'expose-loader',
                options: '$'
            }]
        }
    ]
},
plugins: [
    // Provides jQuery for other JS bundled with Webpack
    new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery'
    })
]
}

更新2

经过几个月的闲置,我几天前又把它捡了起来。我最终通过scalajs-bundler与Webpack合作。

点击here获取解决方案。

0 个答案:

没有答案