@@ -4,8 +4,7 @@ import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
4
4
import sbt .Keys ._
5
5
import sbt ._
6
6
import scommons .sbtplugin .util .{BundlesUtils , ResourcesUtils }
7
-
8
- import scalajsbundler .Webpack
7
+ import scalajsbundler .{NpmPackage , Webpack }
9
8
import scalajsbundler .sbtplugin .ScalaJSBundlerPlugin
10
9
import scalajsbundler .sbtplugin .ScalaJSBundlerPlugin .autoImport ._
11
10
@@ -99,18 +98,33 @@ object ScommonsPlugin extends AutoPlugin {
99
98
val nodeArgs = (Test / webpackNodeArgs).value
100
99
val bundleName = bundleOutput.data.name.stripSuffix(" .js" )
101
100
val webpackOutput = targetDir / s " $bundleName-webpack-out.js "
101
+ val webpackVersion = (webpack / version).value
102
102
103
103
logger.info(" Executing webpack..." )
104
104
val loader = bundleOutput.data
105
105
106
- customWebpackConfigFile match {
106
+ val configArgs = customWebpackConfigFile match {
107
107
case Some (configFile) =>
108
108
val customConfigFileCopy = Webpack .copyCustomWebpackConfigFiles(targetDir, webpackResources.value.get)(configFile)
109
- Webpack .run( nodeArgs : _* )( " --mode " , " development " , " -- config" , customConfigFileCopy.getAbsolutePath, loader.absolutePath, " --output " , webpackOutput.absolutePath)(targetDir, logger )
109
+ Seq ( " --config" , customConfigFileCopy.getAbsolutePath)
110
110
case None =>
111
- Webpack .run( nodeArgs : _* )( " --mode " , " development " , loader.absolutePath, " --output " , webpackOutput.absolutePath)(targetDir, logger)
111
+ Seq .empty
112
112
}
113
113
114
+ val allArgs = Seq (
115
+ " --entry" , loader.absolutePath,
116
+ " --output-path" , targetDir.absolutePath,
117
+ " --output-filename" , webpackOutput.name
118
+ ) ++ configArgs
119
+
120
+ NpmPackage (webpackVersion).major match {
121
+ case Some (5 ) =>
122
+ Webpack .run(nodeArgs : _* )(allArgs : _* )(targetDir, logger)
123
+ case Some (x) =>
124
+ sys.error(s " Unsupported webpack major version $x" )
125
+ case None =>
126
+ sys.error(" No webpack version defined" )
127
+ }
114
128
Attributed (webpackOutput)(bundleOutput.metadata)
115
129
}
116
130
else bundleOutput
0 commit comments