Skip to content

Commit

Permalink
fix: babel settings and rollup (#151)
Browse files Browse the repository at this point in the history
Former-commit-id: 5901ea3
Former-commit-id: 63b21748045559afe7572f2e0539605e5d5896ec
  • Loading branch information
jpoehnelt authored May 7, 2020
1 parent c197bb8 commit 213cd3d
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 53 deletions.
9 changes: 4 additions & 5 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"presets": [
[
"@babel/preset-env",
"@babel/env",
{
"targets": {
"browsers": ["last 2 versions", ">1%"]
"browsers": "ie>=11, > 1%"
},
"corejs": "3.6",
"useBuiltIns": "usage"
}
]
],
"sourceType": "script"
}
]
}
2 changes: 1 addition & 1 deletion package-lock.json.REMOVED.git-id

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"ci": "npm run build && npm run test",
"defaults:data:merge": "lerna exec '../../build/merge_default_data.sh'",
"defaults:package:merge": "lerna exec '../../build/merge_default_package.sh'",
"extract:public": "mkdir -p public && tar -xf dist/bin/public.tar -C public",
"extract:master": "mkdir -p master/public && tar -xf dist/bin/public.tar -C master/public",
"extract:public": "mkdir -p public && tar -xf dist/bin/public.tar -C public",
"format": "npm run format:root && lerna run format",
"format:dist": "lerna run format:dist",
"format:root": "sort-package-json && prettier *.json *.js shared/**/*.scss --write --loglevel error",
Expand All @@ -34,15 +34,18 @@
},
"dependencies": {},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"@babel/runtime-corejs3": "^7.9.6",
"@bazel/bazel": "^1.1.0",
"@bazel/buildifier": "^0.26.0",
"@bazel/buildozer": "^0.29.0",
"@bazel/rollup": "0.42.1",
"@rollup/plugin-babel": "^5.0.0",
"@rollup/plugin-commonjs": "^11.1.0",
"@rollup/plugin-node-resolve": "^7.1.3",
"@types/googlemaps": "^3.37.7",
"core-js": "^3.6.5",
"eslint": "^6.5.1",
"eslint-config-prettier": "^6.4.0",
"eslint-plugin-jest": "^22.19.0",
Expand All @@ -55,7 +58,6 @@
"nunjucks-cli": "git+https://github.com/jpoehnelt/nunjucks-cli.git#a6c17c60a5e7fda4fbc8a73c0abf8af5750ff48c",
"prettier": "^1.18.2",
"rollup": "^2.0.0",
"rollup-plugin-strip-banner": "^2.0.0",
"web-resource-inliner": "^4.3.4"
}
}
18 changes: 11 additions & 7 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
* limitations under the License.
*/

import babel from "@rollup/plugin-babel";
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";

module.exports = {
output: {
format: "iife",
extend: "window",
name: "window",
treeshake: false
}
};
output: {
format: "iife",
extend: "window",
name: "window"
},
plugins: [babel({ babelHelpers: "bundled" }), resolve(), commonjs()]
};
7 changes: 3 additions & 4 deletions rules/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ nodejs_binary(
nodejs_binary(
name = "inline",
data = [
"@npm//:node_modules",
"inline.js",
"@npm//:node_modules",
],
entry_point = ":inline.js",
visibility = ["//visibility:public"],

)
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion rules/inline.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ def inline(src, out, sources):
outs = [out],
cmd = "$(location //rules:inline) $(location {}) $@ && $(location //rules:prettier) --write $@".format(src),
tools = ["//rules:inline", "//rules:prettier"],
)
)
2 changes: 1 addition & 1 deletion rules/prettier.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ def prettier(src, out):
outs = [out],
cmd = "./$(location //rules:prettier) $(location {}) > $@".format(src),
tools = ["//rules:prettier"],
)
)
45 changes: 17 additions & 28 deletions rules/sample.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
load("@npm//@babel/cli:index.bzl", "babel")
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
load("//rules:nunjucks.bzl", "nunjucks")
load("//rules:strip_region_tags.bzl", "strip_region_tags")
Expand All @@ -17,37 +16,27 @@ def _set_data_field(name, src, out, field, value):
def sample():
""" generates the various outputs"""
strip_region_tags(
name = "_js_without_region_tags",
name = "_app_without_region_tags",
input = ":src/index.js",
output = "_without_region_tags.js",
output = "_app_without_region_tags.js",
)

rollup_bundle(
name = "app_ugly",
srcs = [":_js_without_region_tags"],
entry_point = "_without_region_tags.js",
name = "_app_ugly",
srcs = [":_app_without_region_tags.js", "//:.babelrc"],
entry_point = "_app_without_region_tags.js",
config_file = "//:rollup.config.js",
format = "iife",
sourcemap = "false",
visibility = ["//visibility:public"],
)

babel(
name = "transpiled",
args = [
"$(location :app_ugly)",
"-f",
"$(location //:.babelrc)",
"--out-file",
"$@",
],
data = [
":app_ugly",
deps = [
"@npm//@rollup/plugin-commonjs",
"@npm//@rollup/plugin-babel",
"@npm//@babel/core",
"@npm//@babel/runtime-corejs3",
"@npm//@babel/preset-env",
"//:.babelrc",
"@npm//@rollup/plugin-node-resolve",
"@npm//core-js",
],
outs = ["transpiled_ugly.js"],
visibility = ["//visibility:public"],
)

sass_binary(
Expand Down Expand Up @@ -94,13 +83,13 @@ def sample():
strip_region_tags(
name = "_jsfiddle_strip_region_tags",
input = ":_jsfiddle.html",
output = "jsfiddle_ugly.html",
output = "_jsfiddle_ugly.html",
)

for src, out in [
(":jsfiddle_ugly.html", "jsfiddle.html"),
(":_jsfiddle_ugly.html", "jsfiddle.html"),
(":style_ugly.css", "style.css"),
(":transpiled_ugly.js", "transpiled.js"),
(":_app_ugly.js", "app.js"),
]:
prettier(
src = src,
Expand Down Expand Up @@ -130,7 +119,7 @@ def sample():

native.genrule(
name = "_index_with_tags",
srcs = [":_index_rendered.html", ":transpiled.js", ":style.css"],
srcs = [":_index_rendered.html", ":app.js", ":style.css"],
outs = ["_index_with_tags.html"],
cmd = "$(location //rules:inline) $(location :_index_rendered.html) $@",
tools = ["//rules:inline"],
Expand All @@ -150,7 +139,7 @@ def sample():
native.filegroup(
name = "js",
srcs = [
":transpiled.js",
":app.js",
],
visibility = ["//visibility:public"],
)
Expand Down
2 changes: 1 addition & 1 deletion rules/strip_region_tags.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def _strip_region_tags_impl(ctx):
STRIP_REGION_TAGS_CMD = """
set -e
sed '/[[START|END][A-Z_]* .*\\]/d' $1 > $2
sed '/\\[(START|END) [a-z_]*\\]/d' $1 > $2
"""
in_file = ctx.file.input
out_file = ctx.outputs.output
Expand Down
4 changes: 2 additions & 2 deletions shared/layout.njk
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
{% endblock %}
{% block js %}
{% if inline %}
<script src="./transpiled.js" data-inline></script>
<script src="./app.js" data-inline></script>
{% else %}
<script src="./transpiled.js"></script>
<script src="./app.js"></script>
{% endif %}
{% endblock %}
{{ api() }}
Expand Down

0 comments on commit 213cd3d

Please sign in to comment.