diff --git a/.travis.yml b/.travis.yml index 64235ba..b9ff566 100644 --- a/.travis.yml +++ b/.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 diff --git a/src/main/g8/build.sbt b/src/main/g8/build.sbt index e78f4fa..449c8a6 100644 --- a/src/main/g8/build.sbt +++ b/src/main/g8/build.sbt @@ -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() diff --git a/src/main/g8/hot-launcher.js b/src/main/g8/hot-launcher.js deleted file mode 100644 index 04cbb8e..0000000 --- a/src/main/g8/hot-launcher.js +++ /dev/null @@ -1,5 +0,0 @@ -require("./$name$-fastopt.js").entrypoint.main(); - -if (module.hot) { - module.hot.accept(); -} diff --git a/src/main/g8/opt-launcher.js b/src/main/g8/opt-launcher.js deleted file mode 100644 index c40552b..0000000 --- a/src/main/g8/opt-launcher.js +++ /dev/null @@ -1 +0,0 @@ -require("./$name$-opt.js").entrypoint.main(); diff --git a/src/main/g8/public/index-fastopt.html b/src/main/g8/public/index-fastopt.html deleted file mode 100644 index aa98956..0000000 --- a/src/main/g8/public/index-fastopt.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - React App - - - -
- - - - - - - diff --git a/src/main/g8/webpack-fastopt.config.js b/src/main/g8/webpack-fastopt.config.js deleted file mode 100644 index 13e41ca..0000000 --- a/src/main/g8/webpack-fastopt.config.js +++ /dev/null @@ -1,29 +0,0 @@ -var merge = require('webpack-merge'); -var core = require('./webpack-core.config.js') -var path = require("path"); -var HtmlWebpackPlugin = require('html-webpack-plugin'); - -module.exports = merge(core, { - entry: { - "dependencies": ["./$name$-fastopt-entrypoint.js"], - "$name$-fastopt": ["./hot-launcher.js"] - }, - output: { - path: __dirname, - filename: "[name]-library.js", - library: "appLibrary", - libraryTarget: "var" - }, - devtool: "source-map", - module: { - noParse: (content) => { - return content.endsWith("-fastopt.js"); - } - }, - plugins: [ - new HtmlWebpackPlugin({ - template: path.resolve(__dirname, "../../../../public/index-fastopt.html"), - inject: false - }) - ] -}) diff --git a/src/main/g8/webpack-opt.config.js b/src/main/g8/webpack-opt.config.js deleted file mode 100644 index fc08174..0000000 --- a/src/main/g8/webpack-opt.config.js +++ /dev/null @@ -1,26 +0,0 @@ -var merge = require('webpack-merge'); -var core = require('./webpack-core.config.js') -var webpack = require("webpack"); -var path = require("path"); -var HtmlWebpackPlugin = require('html-webpack-plugin'); - -module.exports = merge(core, { - mode: "production", - entry: { - "$name$-opt": [ path.resolve(__dirname, "./opt-launcher.js") ] - }, - output: { - "path": path.resolve(__dirname, "../../../../build"), - "filename": "[name]-bundle.js" - }, - plugins: [ - new HtmlWebpackPlugin({ - template: path.resolve(__dirname, "../../../../public/index.html") - }), - new webpack.DefinePlugin({ - 'process.env': { - NODE_ENV: JSON.stringify('production') - } - }) - ] -}) diff --git a/src/main/g8/webpack/scalajs-entry.js b/src/main/g8/webpack/scalajs-entry.js new file mode 100644 index 0000000..0a5dd15 --- /dev/null +++ b/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(); + } +} diff --git a/src/main/g8/webpack-core.config.js b/src/main/g8/webpack/webpack-core.config.js similarity index 65% rename from src/main/g8/webpack-core.config.js rename to src/main/g8/webpack/webpack-core.config.js index 8baa8a1..a49f19f 100644 --- a/src/main/g8/webpack-core.config.js +++ b/src/main/g8/webpack/webpack-core.config.js @@ -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: [ @@ -34,6 +35,9 @@ module.exports = { plugins: [ new CopyWebpackPlugin([ { from: path.resolve(__dirname, "../../../../public") } - ]) + ]), + new HtmlWebpackPlugin({ + template: path.resolve(__dirname, "../../../../public/index.html") + }) ] } diff --git a/src/main/g8/webpack/webpack-fastopt.config.js b/src/main/g8/webpack/webpack-fastopt.config.js new file mode 100644 index 0000000..651e133 --- /dev/null +++ b/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"); + } + } +}) diff --git a/src/main/g8/webpack/webpack-opt.config.js b/src/main/g8/webpack/webpack-opt.config.js new file mode 100644 index 0000000..5a8854a --- /dev/null +++ b/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') + } + }) + ] +})