Skip to content
This repository has been archived by the owner on Jun 5, 2021. It is now read-only.

Commit

Permalink
Move to webpack-dev-server (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Compton authored and fwouts committed Nov 21, 2018
1 parent 68f8fbb commit b61c90d
Show file tree
Hide file tree
Showing 5 changed files with 809 additions and 827 deletions.
2 changes: 1 addition & 1 deletion internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"typescript": "^2.9.2",
"uglifyjs-webpack-plugin": "^1.2.7",
"webpack": "^4.16.0",
"webpack-serve": "^2.0.2"
"webpack-dev-server": "^3.1.9"
}
}
1 change: 1 addition & 0 deletions internal/web_bundle/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package(default_visibility = ["//visibility:public"])
exports_files([
"compile.js",
"create_webpack_config.js",
"dev_server_options.js",
"rule.bzl",
])
7 changes: 7 additions & 0 deletions internal/web_bundle/dev_server_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const options = {
hot: true,
inline: true,
contentBase: "/"
};

module.exports = options;
28 changes: 24 additions & 4 deletions internal/web_bundle/rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def _web_bundle_dev_server_impl(ctx):
content = """
const fs = require("fs-extra");
const path = require("path");
const serve = require("webpack-serve");
const chokidar = require("chokidar");
// We cannot build directly from the source directory as Webpack struggles to
Expand Down Expand Up @@ -126,10 +125,25 @@ if (config.mode === "production") {{
process.exit(1);
}}
serve({{}}, {{
config,
hot: true,
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const port = 8080;
var options = require(path.resolve("{dev_server_options}"));
options.publicPath = config.output.publicPath;
const server = new WebpackDevServer(webpack(config), options);
server.listen(port, 'localhost', function (err) {{
if (err) {{
console.log(err);
}} else {{
console.log('WebpackDevServer listening at localhost:', port);
}}
}});
""".format(
webpack_config = webpack_config.short_path,
# Directory containing the compiled source code of the js_library.
Expand All @@ -152,6 +166,7 @@ serve({{}}, {{
internal_packages_dir = ctx.attr._internal_packages[NpmPackagesInfo].installed_dir.short_path,
# Template index.html for Webpack.
html_template = ctx.file.html_template.short_path if ctx.file.html_template else "",
dev_server_options = ctx.attr.lib[JsLibraryInfo].compiled_javascript_dir.short_path + "/" + ctx.file.dev_server_options.short_path,
),
)
ctx.actions.write(
Expand Down Expand Up @@ -280,6 +295,11 @@ _ATTRS = {
],
default = "umd",
),
"dev_server_options": attr.label(
allow_files = True,
single_file = True,
default = Label("//internal/web_bundle:dev_server_options.js"),
),
"_internal_nodejs": attr.label(
allow_files = True,
single_file = True,
Expand Down
Loading

0 comments on commit b61c90d

Please sign in to comment.