我将jQuery modal dialog plugin 与jQuery facade一起使用。它一直有效,直到我决定使用scala-bundler从jsDependencies
更改为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)
在我使用自定义$
公开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'
})
]
}
经过几个月的闲置,我几天前又把它捡了起来。我最终通过scalajs-bundler与Webpack合作。
点击here获取解决方案。