### Complete Project BUILD File Source: https://context7.com/bazelbuild/rules_closure/llms.txt A comprehensive `BUILD` file example demonstrating the setup of JavaScript libraries, binaries, and tests using `rules_closure` for a Bazel project. ```starlark # BUILD load("@rules_closure//closure:defs.bzl", "closure_js_library", "closure_js_binary", "closure_js_test") closure_js_library( name = "mylib", srcs = glob(["*.js"], exclude=["*_test.js"]), deps = [], ) closure_js_binary( name = "myapp", deps = [":mylib"], entry_points = ["myapp.main"], ) closure_js_test( name = "mylib_test", srcs = glob(["*_test.js"]), deps = [ ":mylib", "//closure/testing/library:asserts", "//closure/testing/library:jsunit", ], ) ``` -------------------------------- ### Bazel Command Line Examples Source: https://context7.com/bazelbuild/rules_closure/llms.txt Provides common Bazel commands for building JavaScript binaries, running tests, and building with different compilation levels. ```bash # Build JavaScript binary bazel build //:myapp # Run tests bazel test //:mylib_test # Build with different compilation levels bazel build //:myapp --define=COMPILATION_LEVEL=SIMPLE ``` -------------------------------- ### CSS Content Example Source: https://context7.com/bazelbuild/rules_closure/llms.txt A simple CSS file content example. ```css /* hello.css */ .immutable-pain { font-weight: bold; } ``` -------------------------------- ### closure_js_test: Run JavaScript Unit Tests Source: https://github.com/bazelbuild/rules_closure/blob/master/README.md Executes JavaScript unit tests within a headless web browser using a macro that integrates closure_js_library, closure_js_binary, and phantomjs_test. Tests are identified by functions starting with 'test', 'setUp', or 'tearDown' and require goog.testing.jsunit and goog.testing.asserts. Network access is restricted, but runfiles are accessible via a local HTTP server. ```starlark load("@rules_closure//closure:defs.bzl", "closure_js_test") closure_js_test(name, srcs, data, deps, css, html, language, suppress, compilation_level, entry_points, defs) ``` -------------------------------- ### JavaScript Binary Output Examples Source: https://context7.com/bazelbuild/rules_closure/llms.txt Illustrates different output formats for JavaScript binaries compiled with `closure_js_binary`, including minified, wrapped, and strict mode outputs. ```javascript // Input: console.log('hello world'); // Output (ADVANCED): console.log("hello world"); // Output (with wrapper): (function(){console.log("hello world");}).call(this); // Output (strict): 'use strict';console.log("hello world"); ``` -------------------------------- ### JavaScript Unit Test Example (Google Closure) Source: https://context7.com/bazelbuild/rules_closure/llms.txt A JavaScript file containing unit tests written using Google Closure's testing library (`goog.testing.asserts` and `goog.testing.jsunit`). It includes a simple test case for addition. ```javascript // simple_test.js goo ``` -------------------------------- ### JavaScript Code Referencing CSS Classes Source: https://context7.com/bazelbuild/rules_closure/llms.txt An example JavaScript file showing how to reference CSS classes using `goog.getCssName` for integration with Closure Compiler's renaming capabilities. ```javascript // app.js - JavaScript code references CSS classes goo.provide('myapp'); myapp.render = function() { var element = document.createElement('div'); element.className = goog.getCssName('immutable-pain'); document.body.appendChild(element); }; ``` -------------------------------- ### Compile CSS Binary with Starlark Source: https://context7.com/bazelbuild/rules_closure/llms.txt Compiles stylesheets into minified CSS with class name renaming and sourcemap generation using `closure_css_binary`. Supports debug mode and different orientations. ```starlark load("@rules_closure//closure:defs.bzl", "closure_css_binary") closure_css_binary( name = "hello_rename_bin", deps = [":hello_lib"], renaming = True, ) closure_css_binary( name = "hello_dbg", deps = [":hello_lib"], debug = True, renaming = False, ) closure_css_binary( name = "rtl_bin", deps = [":hello_lib"], orientation = "RTL", ) ``` -------------------------------- ### phantomjs_test: Execute PhantomJS for Unit Testing Source: https://github.com/bazelbuild/rules_closure/blob/master/README.md A low-level rule for running PhantomJS (QtWebKit) for unit testing purposes. It's recommended to use the higher-level closure_js_test macro when possible. This rule takes dependencies on Skylark rules that export transitive_js_srcs and can be configured with custom HTML and runner scripts. ```starlark load("@rules_closure//closure:defs.bzl", "phantomjs_test") phantomjs_test(name, data, deps, html, harness, runner) ``` -------------------------------- ### Create CSS Binary with closure_css_binary Source: https://github.com/bazelbuild/rules_closure/blob/master/README.md The closure_css_binary rule takes CSS libraries and minifies them into a single CSS file. It handles Closure-specific syntax, minifies class names by default, and produces CSS, sourcemaps, and CSS name mapping files. ```starlark load("@rules_closure//closure:defs.bzl", "closure_css_binary") closure_css_binary( name = "my_css_binary", deps = [ ":my_css_lib", "@rules_closure//closure:prelude.css", ], renaming = "ALL", debug = "NONE", ) ``` -------------------------------- ### Integrate CSS and JavaScript with Starlark Source: https://context7.com/bazelbuild/rules_closure/llms.txt Demonstrates linking CSS class name renaming between JavaScript and CSS binaries for coordinated minification. Uses `closure_css_library`, `closure_css_binary`, `closure_js_library`, and `closure_js_binary`. ```starlark load("@rules_closure//closure:defs.bzl", "closure_js_library", "closure_js_binary", "closure_css_library", "closure_css_binary") closure_css_library( name = "styles_lib", srcs = ["styles.css"], ) closure_css_binary( name = "styles_bin", deps = [":styles_lib"], renaming = True, ) closure_js_library( name = "app_lib", srcs = ["app.js"], deps = [":styles_lib"], ) closure_js_binary( name = "app_bin", deps = [":app_lib"], css = ":styles_bin", ) ``` -------------------------------- ### MODULE.bazel for Rules Closure Source: https://context7.com/bazelbuild/rules_closure/llms.txt Specifies the dependency on the `rules_closure` Bazel repository in the `MODULE.bazel` file. ```starlark # MODULE.bazel bazel_dep(name = "rules_closure", version = "0.15.0") ``` -------------------------------- ### ES6 JavaScript Input and Output Source: https://context7.com/bazelbuild/rules_closure/llms.txt Illustrates the input ES6 JavaScript code and its transpiled ES3 output after processing with Closure Compiler. ```javascript // Input es6const.js const hello = 'hello world'; console.log(hello); // Output es6const_bin.js var hello="hello world";console.log(hello); ``` -------------------------------- ### Run JavaScript Unit Tests with Bazel (Starlark) Source: https://context7.com/bazelbuild/rules_closure/llms.txt Executes JavaScript unit tests in a headless browser using the `closure_js_test` rule. It automatically discovers and runs tests, accepting source files (`srcs`), dependencies (`deps`), and entry points. Supports various compilation levels. ```starlark load("@rules_closure//closure:defs.bzl", "closure_js_test") closure_js_test( name = "simple_test", timeout = "short", srcs = ["simple_test.js"], deps = [ "//closure/testing/library:asserts", "//closure/testing/library:jsunit", ], ) closure_js_test( name = "arithmetic_module_test", srcs = ["arithmetic_module_test.js"], entry_points = ["goog:arithmetic_module_test"], deps = [ ":arithmetic_module_lib", "//closure/testing/library:asserts", "//closure/testing/library:jsunit", "//closure/testing/library:testsuite", ], compilation_level = "WHITESPACE_ONLY", ) ``` -------------------------------- ### Compile JavaScript Binary with Bazel (Starlark) Source: https://context7.com/bazelbuild/rules_closure/llms.txt Compiles and minifies JavaScript libraries into an optimized single-file output with sourcemaps using the `closure_js_binary` rule. It accepts dependencies (`deps`), compilation level, language, and output wrapper. Debugging can be enabled with `debug = True`. ```starlark load("@rules_closure//closure:defs.bzl", "closure_js_binary") closure_js_binary( name = "hello_bin", deps = [":hello_lib"], compilation_level = "ADVANCED", language = "ECMASCRIPT3", output_wrapper = "(function(){%output%}).call(this);", ) closure_js_binary( name = "hello_strict_bin", deps = [":hello_lib"], defs = ["--emit_use_strict=True"], ) closure_js_binary( name = "hello_dbg", deps = [":hello_lib"], debug = True, compilation_level = "WHITESPACE_ONLY", ) ``` -------------------------------- ### Generate Property Renaming Report with closure_js_binary Source: https://context7.com/bazelbuild/rules_closure/llms.txt Configures a `closure_js_binary` target to generate a report of minified property names. This is useful for advanced debugging or analysis of the minification process. The report is saved to a specified file. ```starlark closure_js_binary( name = "app_with_report", deps = [":app_lib"], property_renaming_report = "renaming_report.txt", ) ``` -------------------------------- ### closure_css_library: Define CSS Stylesheets Source: https://github.com/bazelbuild/rules_closure/blob/master/README.md Defines a set of CSS stylesheets without compiling them. This rule is intended for use with closure_css_binary, which handles the minification. It should be referenced by any closure_js_library rule that uses goog.getCssName() for CSS class names defined within this library. ```starlark load("@rules_closure//closure:defs.bzl", "closure_css_library") closure_css_library(name, srcs, data, deps) ``` -------------------------------- ### JavaScript Library Source Code (Google Closure) Source: https://context7.com/bazelbuild/rules_closure/llms.txt A JavaScript file defining a namespace and a function using Google Closure's `goog.provide` and standard JSDoc for documentation. This serves as an input for `closure_js_library`. ```javascript // arithmetic.js goog.provide('io.bazel.rules.closure.arithmetic'); /** * Adds two numbers. * @param {number} a * @param {number} b * @return {number} */ io.bazel.rules.closure.arithmetic.add = function(a, b) { return a + b; }; ``` -------------------------------- ### ES6 Transpilation with Starlark Source: https://context7.com/bazelbuild/rules_closure/llms.txt Compiles modern JavaScript (ES6) to ES3 for broader browser compatibility using `closure_js_library` and `closure_js_binary`. It includes options for disabling Closure Library and specifying the output language. ```starlark closure_js_library( name = "es6const_lib", srcs = ["es6const.js"], no_closure_library = True, ) closure_js_binary( name = "es6const_bin", deps = [":es6const_lib"], compilation_level = "WHITESPACE_ONLY", language = "ECMASCRIPT5", ) ``` -------------------------------- ### Define JavaScript Library with Bazel (Starlark) Source: https://context7.com/bazelbuild/rules_closure/llms.txt Defines a set of JavaScript source files as a reusable library with strict dependency checking and linting using the `closure_js_library` rule. It takes source files (`srcs`) and dependencies (`deps`) as input. It also supports linting suppression and convention specification. ```starlark load("@rules_closure//closure:defs.bzl", "closure_js_library") closure_js_library( name = "arithmetic_lib", srcs = ["arithmetic.js"], deps = [], ) closure_js_library( name = "calculator_lib", srcs = ["calculator.js"], deps = [":arithmetic_lib"], suppress = ["lintChecks"], convention = "CLOSURE", ) ``` -------------------------------- ### Define CSS Library with Starlark Source: https://context7.com/bazelbuild/rules_closure/llms.txt Defines a CSS or GSS stylesheet source with support for dependencies and orientation settings using the `closure_css_library` rule. It takes source files and can include data dependencies. ```starlark load("@rules_closure//closure:defs.bzl", "closure_css_library") closure_css_library( name = "hello_lib", srcs = ["hello.css"], data = ["images/logo.png"], orientation = "LTR", ) closure_css_library( name = "theme_lib", srcs = ["theme.css"], deps = [":hello_lib"], ) ``` -------------------------------- ### Define a JavaScript library in Bazel using closure_js_library Source: https://github.com/bazelbuild/rules_closure/blob/master/README.md This Starlark code defines a JavaScript library target for Bazel. The closure_js_library rule is used to declare an abstract graph of JavaScript sources and is typically used with closure_js_binary for outputting a minified file. It performs syntax checking and linting, with options to suppress warnings. ```starlark load("@rules_closure//closure:defs.bzl", "closure_js_library") closure_js_library(name, srcs, data, deps, exports, suppress, convention, no_closure_library) ``` -------------------------------- ### Define CSS Library with closure_css_library Source: https://github.com/bazelbuild/rules_closure/blob/master/README.md The closure_css_library rule compiles GSS/CSS source files into a single CSS file. It supports features like @provide and @require for dependency management and ordering. Outputs can be LTR or RTL oriented. ```starlark load("@rules_closure//closure:defs.bzl", "closure_css_library") closure_css_library( name = "my_css_lib", srcs = ["style.gss"], deps = [":other_lib"], orientation = "LTR", ) ``` -------------------------------- ### closure_js_binary Rule Definition Source: https://github.com/bazelbuild/rules_closure/blob/master/README.md Defines the closure_js_binary rule, which compiles JavaScript libraries into a minified optimized blob of code. This rule is intended for use with closure_js_library. It generates a minified JavaScript file and a corresponding sourcemap file. ```starlark load("@rules_closure//closure:defs.bzl", "closure_js_binary") closure_js_binary(name, deps, css, debug, language, entry_points, dependency_mode, compilation_level, formatting, output_wrapper, property_renaming_report, defs) ``` -------------------------------- ### Add rules_closure dependency to Bazel module Source: https://github.com/bazelbuild/rules_closure/blob/master/README.md This snippet shows how to add the rules_closure dependency to your Bazel project's MODULE.bazel file. It specifies the version of rules_closure to be fetched. Ensure that root modules declare overrides for related dependencies if needed. ```bzl bazel_dep(name = "rules_closure", version = "0.15.0") ``` -------------------------------- ### AngularJS Support with Starlark Source: https://context7.com/bazelbuild/rules_closure/llms.txt Configures Closure Compiler flags for AngularJS applications using the `closure_js_binary` rule. It enables specific passes like `--angular_pass`. ```starlark closure_js_binary( name = "angular_app_bin", deps = [":angular_app_lib"], defs = [ "--angular_pass", "--export_local_property_definitions", ], ) ``` -------------------------------- ### Closure Compiler Custom Flags for AngularJS Source: https://github.com/bazelbuild/rules_closure/blob/master/README.md This snippet demonstrates how to pass custom flags to the Closure Compiler when compiling AngularJS applications. It utilizes the `defs` attribute within a `closure_js_binary` rule to enable specific passes like `--angular_pass` and `--export_local_property_definitions`. ```starlark closure_js_binary( # ... defs = [ "--angular_pass", "--export_local_property_definitions", ], ) ``` -------------------------------- ### Lisp Expression Evaluation Function Source: https://github.com/bazelbuild/rules_closure/blob/master/closure/testing/test/fontdemo.html This Lisp function, `eval.`, recursively evaluates expressions based on different conditions. It handles atoms, symbolic expressions, quotes, and constructs like 'cond', 'label', and 'lambda'. Dependencies include standard Lisp functions like `assoc.`, `atom`, `eq`, `car`, `cdr`, `cons`, `cadr`, `caddr`, `caar`, `caddar`, `cadar`, `caar`, `evcon.`, `eval.`, `cons`, `assoc.`, `cdr`, `a`, `caddar`, `cadar`, `car`, `e`, `append.`, `pair.`, `cadar`, `cadr`, and `evlis.`. Inputs are an expression `e` and an environment `a`. Outputs are the evaluated result or an associated value. Limitations may include stack depth for deeply nested expressions and specific Lisp dialect compatibility. ```lisp (defun eval. (e a) (cond ((atom e) (assoc. e a)) ((atom (car e)) (cond ((eq (car e) 'quote) (cadr e)) ((eq (car e) 'atom) (atom (eval. (cadr e) a))) ((eq (car e) 'eq) (eq (eval. (cadr e) a) (eval. (caddr e) a))) ((eq (car e) 'car) (car (eval. (cadr e) a))) ((eq (car e) 'cdr) (cdr (eval. (cadr e) a))) ((eq (car e) 'cons) (cons (eval. (cadr e) a) (eval. (caddr e) a))) ((eq (car e) 'cond) (evcon. (cdr e) a)) ('t (eval. (cons (assoc. (car e) a) (cdr e)) a)))) ((eq (caar e) 'label) (eval. (cons (caddar e) (cdr e)) (cons (list. (cadar e) (car e)) a))) ((eq (caar e) 'lambda) (eval. (caddar e) (append. (pair. (cadar e) (evlis. (cdr e) a)) a)))) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.