Skip to content

Commit

Permalink
Generate a single bundle for fastopt mode and include configuration f…
Browse files Browse the repository at this point in the history
…or reverse-interop (#6)

* Generate a single bundle for fastopt mode and include configuration for reverse-interop

* Move Webpack config into separate folder

* Fix Webpack config file paths
  • Loading branch information
shadaj committed Sep 19, 2018
1 parent 2dcd338 commit 83389f3
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 117 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
@@ -1,6 +1,9 @@
language: scala

# These directories are cached to S3 at the end of the build
branches:
only:
- master

cache:
directories:
- $HOME/.ivy2/cache
Expand Down
8 changes: 4 additions & 4 deletions src/main/g8/build.sbt
Expand Up @@ -21,16 +21,16 @@ libraryDependencies += "me.shadaj" %%% "slinky-hot" % "0.4.3"
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.0.5" % Test

scalacOptions += "-P:scalajs:sjsDefinedByDefault"

addCompilerPlugin("org.scalameta" % "paradise" % "3.0.0-M11" cross CrossVersion.full)

version in webpack := "4.5.0"
version in startWebpackDevServer:= "3.1.3"

webpackConfigFile in fastOptJS := Some(baseDirectory.value / "webpack-fastopt.config.js")
webpackConfigFile in fullOptJS := Some(baseDirectory.value / "webpack-opt.config.js")
webpackResources := baseDirectory.value / "webpack" * "*"

webpackConfigFile in Test := Some(baseDirectory.value / "webpack-core.config.js")
webpackConfigFile in fastOptJS := Some(baseDirectory.value / "webpack" / "webpack-fastopt.config.js")
webpackConfigFile in fullOptJS := Some(baseDirectory.value / "webpack" / "webpack-opt.config.js")
webpackConfigFile in Test := Some(baseDirectory.value / "webpack" / "webpack-core.config.js")

webpackDevServerExtraArgs in fastOptJS := Seq("--inline", "--hot")
webpackBundlingMode in fastOptJS := BundlingMode.LibraryOnly()
Expand Down
5 changes: 0 additions & 5 deletions src/main/g8/hot-launcher.js

This file was deleted.

1 change: 0 additions & 1 deletion src/main/g8/opt-launcher.js

This file was deleted.

45 changes: 0 additions & 45 deletions src/main/g8/public/index-fastopt.html

This file was deleted.

29 changes: 0 additions & 29 deletions src/main/g8/webpack-fastopt.config.js

This file was deleted.

26 changes: 0 additions & 26 deletions src/main/g8/webpack-opt.config.js

This file was deleted.

17 changes: 17 additions & 0 deletions src/main/g8/webpack/scalajs-entry.js
@@ -0,0 +1,17 @@
if (process.env.NODE_ENV === "production") {
const opt = require("./$name$-opt.js");
opt.entrypoint.main();
module.exports = opt;
} else {
var exports = window;
exports.require = require("./$name$-fastopt-entrypoint.js").require;
window.global = window;

const fastOpt = require("./$name$-fastopt.js");
fastOpt.entrypoint.main()
module.exports = fastOpt;

if (module.hot) {
module.hot.accept();
}
}
@@ -1,15 +1,16 @@
var path = require("path");
var CopyWebpackPlugin = require('copy-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
mode: "development",
output: {
"filename": "[name]-bundle.js"
},
resolve: {
alias: {
"resources": path.resolve(__dirname, "../../../../src/main/resources")
}
"resources": path.resolve(__dirname, "../../../../src/main/resources"),
"js": path.resolve(__dirname, "../../../../src/main/js"),
"scalajs": path.resolve(__dirname, "./scalajs-entry.js")
},
modules: [ path.resolve(__dirname, 'node_modules') ]
},
module: {
rules: [
Expand All @@ -34,6 +35,9 @@ module.exports = {
plugins: [
new CopyWebpackPlugin([
{ from: path.resolve(__dirname, "../../../../public") }
])
]),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "../../../../public/index.html")
})
]
}
16 changes: 16 additions & 0 deletions src/main/g8/webpack/webpack-fastopt.config.js
@@ -0,0 +1,16 @@
var merge = require('webpack-merge');
var core = require('./webpack-core.config.js')

var generatedConfig = require("./scalajs.webpack.config.js");
const entries = {};
entries[Object.keys(generatedConfig.entry)[0]] = "scalajs";

module.exports = merge(core, {
devtool: "source-map",
entry: entries,
module: {
noParse: (content) => {
return content.endsWith("-fastopt.js");
}
}
})
19 changes: 19 additions & 0 deletions src/main/g8/webpack/webpack-opt.config.js
@@ -0,0 +1,19 @@
var merge = require('webpack-merge');
var core = require('./webpack-core.config.js')
var webpack = require("webpack");

var generatedConfig = require("./scalajs.webpack.config.js");
const entries = {};
entries[Object.keys(generatedConfig.entry)[0]] = "scalajs";

module.exports = merge(core, {
mode: "production",
entry: entries,
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
})
]
})

0 comments on commit 83389f3

Please sign in to comment.