├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── example ├── README.md ├── build.sbt ├── index.html ├── package.json ├── project │ ├── build.properties │ └── plugins.sbt ├── src │ └── main │ │ └── scala │ │ └── HelloWorld.scala └── webpack.config.js ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git 28 | node_modules 29 | 30 | # Optional npm cache directory 31 | .npm 32 | 33 | # Optional REPL history 34 | .node_repl_history 35 | 36 | *.tgz 37 | 38 | # Example 39 | example/target 40 | example/lib_managed 41 | example/src_managed 42 | example/project/boot 43 | example/.history 44 | example/.cache 45 | example/project/target 46 | example/project/project 47 | example/bundle.js 48 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git 28 | node_modules 29 | 30 | # Optional npm cache directory 31 | .npm 32 | 33 | # Optional REPL history 34 | .node_repl_history 35 | 36 | *.tgz 37 | 38 | example 39 | .npmignore 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Matt Dziuban 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Scala.js Webpack loader 2 | 3 | [![npm](https://img.shields.io/npm/v/scalajs-loader.svg)](https://www.npmjs.com/package/scalajs-loader) 4 | 5 | ### Usage 6 | 7 | This is a simple Webpack loader that shells out to SBT to build a [Scala.js](http://www.scala-js.org) project. 8 | 9 | To use it, first install the package: 10 | 11 | ```bash 12 | $ npm install --save scalajs-loader 13 | ``` 14 | 15 | then configure the loader in your Webpack config: 16 | 17 | ```js 18 | module.exports = { 19 | // ... 20 | module: { 21 | rules: [ 22 | { test: /\.scala$/, loader: 'scalajs-loader' }, 23 | // ... 24 | ] 25 | } 26 | } 27 | ``` 28 | 29 | Make sure you have the `sbt` binary somewhere in your `PATH`. 30 | 31 | ### Example 32 | 33 | Check out the [example](example) directory for a simple Hello World example. 34 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Scala.js Webpack loader example 2 | 3 | This is a simple Hello World example of the [Scala.js Webpack loader](https://www.npmjs.com/package/scalajs-loader). 4 | 5 | ### Install dependencies 6 | 7 | ```bash 8 | $ npm install 9 | ``` 10 | 11 | ### Compile 12 | 13 | ```bash 14 | $ npm run compile 15 | ``` 16 | 17 | ### Serve 18 | 19 | Run 20 | 21 | ```bash 22 | $ npm run serve 23 | ``` 24 | 25 | then open http://localhost:8080 in your browser. 26 | -------------------------------------------------------------------------------- /example/build.sbt: -------------------------------------------------------------------------------- 1 | import sbt._ 2 | import Keys._ 3 | 4 | scalacOptions ++= Seq( 5 | "-deprecation", 6 | "-encoding", "UTF-8", // yes, this is 2 args 7 | "-feature", 8 | "-unchecked", 9 | "-Xfatal-warnings", 10 | "-Xlint", 11 | "-Yno-adapted-args", 12 | "-Ywarn-dead-code", // N.B. doesn't work well with the ??? hole 13 | "-Ywarn-infer-any", 14 | "-Ywarn-numeric-widen", 15 | "-Ywarn-unused", 16 | "-Ywarn-value-discard", 17 | "-Xfuture", 18 | "-Ydelambdafy:method", 19 | "-target:jvm-1.8" 20 | ) 21 | 22 | lazy val project = Project( 23 | "scalajs-loader-example", 24 | file("."), 25 | settings = Seq( 26 | organization := "mrdziuban", 27 | name := "scalajs-loader-example", 28 | version := "1.0", 29 | scalaVersion := "2.12.1", 30 | libraryDependencies ++= Seq("org.scala-js" %%% "scalajs-dom" % "0.9.1") 31 | ) 32 | ).enablePlugins(ScalaJSPlugin) 33 | -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World 5 | 6 | 7 |
8 | 9 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scalajs-loader-example", 3 | "version": "0.0.1", 4 | "description": "", 5 | "author": "Matt Dziuban", 6 | "license": "UNLICENSED", 7 | "scripts": { 8 | "compile": "webpack --progress", 9 | "serve": "http-server" 10 | }, 11 | "dependencies": { 12 | "http-server": "^0.9.0", 13 | "scalajs-loader": "../", 14 | "webpack": "^2.2.1" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=0.13.13 2 | -------------------------------------------------------------------------------- /example/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.14") 2 | -------------------------------------------------------------------------------- /example/src/main/scala/HelloWorld.scala: -------------------------------------------------------------------------------- 1 | package mrdziuban.scalajsLoaderExample 2 | 3 | import org.scalajs.dom.document 4 | import scala.scalajs.js.JSApp 5 | 6 | object HelloWorld extends JSApp { 7 | def main(): Unit = document.getElementById("container").innerHTML = "Hello World" 8 | } 9 | -------------------------------------------------------------------------------- /example/webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | entry: './src/main/scala/HelloWorld.scala', 3 | output: { filename: 'bundle.js' }, 4 | module: { 5 | rules: [ 6 | { test: /\.scala$/, loader: 'scalajs-loader' } 7 | ] 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const exec = require('child_process').exec; 2 | const path = require('path'); 3 | const readFileSync = require('fs').readFileSync; 4 | 5 | module.exports = function(source) { 6 | const callback = this.async(); 7 | const cmd = 'sbt clean fastOptJS scalaVersion'; 8 | 9 | var self = this; 10 | exec(cmd, { cwd: this.options.context }, function(error, stdout, _stderr) { 11 | if (error) { return callback(error, null); } 12 | 13 | const scalaVersion = stdout.toString().trim().split('\n').pop().replace(/\u001b\[0m/g, '').replace(/^\[info\] (\d+\.\d+)(\.\d+)?/, '$1').trim(); 14 | const outDir = path.join(self.options.context, 'target', `scala-${scalaVersion}`); 15 | 16 | const modName = JSON.parse(readFileSync(path.join(outDir, 'classes', 'JS_DEPENDENCIES')).toString()).origin.moduleName; 17 | const outFile = path.join(outDir, `${modName}-fastopt.js`); 18 | 19 | callback( 20 | null, 21 | readFileSync(outFile).toString().replace( 22 | new RegExp(`\\n\/\/# sourceMappingURL=${modName}-fastopt\.js\.map`), 23 | `\n//# sourceMappingURL=${outFile}.map` 24 | ) 25 | ); 26 | }); 27 | }; 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scalajs-loader", 3 | "version": "0.0.1", 4 | "author": "Matt Dziuban", 5 | "description": "Scala.js loader module for webpack", 6 | "dependencies": { 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "git@github.com:mrdziuban/scalajs-loader" 11 | }, 12 | "license": "MIT" 13 | } 14 | --------------------------------------------------------------------------------