- Install Bazel and set up a workspace
- Add
rules_webas agit_repositoryto theWORKSPACEfile
git_repository(
name = "rules_web",
remote = "https://github.com/quittle/rules_web.git",
)
- Load the 3 sets of dependencies in order in your
WORKSPACEfile. It is multi-stage due to the way Bazel handles repository rule loading.
load("@rules_web//:rules_web_deps_1.bzl", "rules_web_dependencies")
rules_web_dependencies()
load("@rules_web//:rules_web_deps_2.bzl", "rules_web_dependencies")
rules_web_dependencies()
load("@rules_web//:rules_web_deps_3.bzl", "rules_web_dependencies")
rules_web_dependencies()
- Load rule files from non-
internal.bzlBazel files.
load("@rules_web//html:html.bzl", "html_page")
load("@rules_web//fonts:fonts.bzl", "font_generator", "minify_ttf")
//css:css.bzl
minify_cssMinified a bunch of CSS files into onesrcsA label list of sources to merge and minify
//fonts:fonts.bzl
font_generatorGenerates a CSS file with thefont-familyrepresenting this group of font files.font_nameThe name of the font that it will be referenced byeotAn optional EOT font file to usettfAn optional TTF font file to usewoffAn optional WOFF font file to usewoff2An optional WOFF2 font file to usesvgAn optional SVG font file to useweightThe weight of these fonts. Defaults tonormalstyleThe style of these fonts. Defaults tonormal
minify_ttfGenerates a smaller version of a TTF font file by renaming glyphs and removing unnessary tables.ttfThe TTF file to shrink
ttf_to_eotConvertes a TTF font file to an EOT font filettfThe TTF file to convert
ttf_to_woffConverts a TTF font file to a WOFF font filettfThe TTF file to convert
ttf_to_woff2Converts a TTF font file to a WOFF2 font filettfThe TTF file to convert
//generate:generate.bzl
generate_variablesGenerates constants for various languagesconfigA JSON file containing the variablesout_cssAn optional CSS file to write the mapping of the variables toout_jsAn optional Javascript file to write the mapping of the variables toout_scssAn optional SCSS file to write the mapping of the variables to
//html:html.bzl
minify_htmlMinifies an HTML filesrcThe HTML file to minify
html_pageBuilds an HTML file including or referencing the provided sourcestemplateAn optional Jinja2 template for the HTML page that overrides the default.configA JSON file that contains basic meta-data about the pagebodyAn HTML file containing the<body>of the page including the body open and closing tags.deferred_js_filesJavascript files that should be downloaded and run only after thewindow'sloadevent has fired.js_filesJavascript files that should be downloaded and run before the body is loaded.css_filesCSS files that should be downloaded and evaluated asynchronously.favicon_imagesA list of favicon images at various sizes. This must be the same length asfavicon_sizesfavicon_sizesA list of ints that represent the square-size of the images infavicon_images. Must be the same length asfavicon_images.depsOther files that may be referrenced by resources in the page.
inject_htmlInject an HTML fragment inside another HTML fragment.outer_htmlThe outer HTML fragment to be inject into.inner_htmlThe inner HTML fragment to inject in.query_selectorThe CSS selector query to find the element inouter_htmlin which to inject.insertion_modeThe method by whichinner_htmlwill be injected intoouter_html.
validate_htmlUses the W3C validator to check an HTML filesrcThe HTML file to validatefail_on_warningOptional flag (defaults to True) to fail the target on warnings as well as errors.
//images/images.bzl
favicon_image_generatorGenerates favicons of various sizesimageThe source imageoutput_filesThe files to generate. Must be the same length asoutput_sizesoutput_sizesA list of ints representing the square-size of the images generated. Must be the same length asoutput_files.allow_upsizingAn optional boolean of whether the build should not fail if the image needs to be stretched larger to generate any of the images. Defaults toFalseallow_stretchingAn optional boolean of whether the build should not fail if the image needs to be distorted to a different aspect-ratio. Defaults toFalse.
minify_pngMinimizes the size of a PNG imagepngThe PNG the shrink.
resize_imageResizes an imageimageThe image to resizewidthOptionally the width of the image to output. If set without height, height will scale proportional to width.heightOptionally the height of the image to output. If set without width, width will scale proportional to height.scaleOptionally the scaling ratio of the image as a string. If set, width and height must not be set.
//js/js.bzl
resource_mapGenerates a Javascript file mapping resources to a deeply nested dictionary representing the file system structure. For example if["src/path/file.txt", "src/other-path/image.png"]were mapped, it would generate{ "src": { "path": "file.txt", "other-path": "image.png" } }.constant_nameThe contant name that holds the dictionary. E.g."RESOURCE_MAP"would map towindow.RESOURCE_MAP.depsThe labels to put in the dictionary.
minify_jsMinifies a Javascript files together into one, smaller file.srcsThe source files to minify and combine.
closure_compileCompiles Javascript files together with the Closure Compiler.srcsThe Javascript files to merge and compile.externsThe external Javascript files whose contents should not be minified in the generated file.compilation_levelThe compilation level to compile with.warning_levelThe warning level to compile with.extra_argsA list of extra arguments to pass to the compiler
//site_zip:site_zip.bzl
zip_siteZips all the sources for a website into one fileroot_filesThe root files of the website that will be requested by the user directly. This should be your base html pages, robots.txt and other resources like that.resoucesAll the possible resources thatroot_filesmight reference to be included in the zip.out_zipThe zip file to generate.
minify_site_zipMinifies a zip file by minifying file names and references in the zip.site_zipThe site zip to minify.root_filesThe root files that will be directly accessed by customers and should not be renamed.minified_zipThe minified zip file to generate.
rename_zip_pathsRenames entries in the zip. This is useful as all generated files will have a path in the bazel-out directorysource_zipThe source zip to renmae entries of.path_map_labels_inA list of labels for the entries insource_zipto rename.path_map_labels_outA list of new names for the entries specified bypath_map_labels_in. The entries in this list map directly to the entries inpath_map_labels_inwith the same index.out_zipThe zip file to generate.
zip_serverRuns a localhost server that serves a zip file. This is not a secure implementation and should only be used for testing.zipThe zip file to server.portThe port to listen on. Defaults to80.
//deploy:deploy.bzl
deploy_site_zip_s3_scriptaws_access_keyThe AWS access key string to useaws_secret_keyThe AWS secret access key string to usebucketThe AWS bucket to upload tozip_fileA zip file whose contents should be uploaded
//images:images.bzl
generate_icoGenerates an ICO image file by resizing a source to multiple sizessourceThe source image to resizesizesA list of sizes to resize thesourceimage toallow_upsizingAn optional boolean of whether the build should not fail if one of the generated sizes is larger than the source image. Defaults toFalse.
If you get an error similar to
ImportError: cannot import name 'sysconfig' from 'distutils'
you will need to apt install python3-distutils