-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(esbuild): add output_css flag to esbuild()
When esbuild encounters an 'import "./foo.css"' file in normal (non-splitting) mode, it will place the contents of that file in a .css file next to the main output .js file. This patch adds a flag output_css, which when set to True, will declare the created .css file as another output, so it can be consumed by other rules.
- Loading branch information
Showing
5 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
load("//packages/esbuild/test:tests.bzl", "esbuild") | ||
load("//packages/jasmine:index.bzl", "jasmine_node_test") | ||
load("//packages/typescript:index.bzl", "ts_library") | ||
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin") | ||
|
||
copy_to_bin( | ||
name = "external_copied", | ||
srcs = ["external.css"], | ||
) | ||
|
||
ts_library( | ||
name = "main", | ||
srcs = [ | ||
"main.ts", | ||
], | ||
deps = [ | ||
"@npm//@types/node", | ||
], | ||
) | ||
|
||
esbuild( | ||
name = "default", | ||
entry_point = "main.ts", | ||
deps = [ | ||
"external_copied", | ||
":main", | ||
], | ||
) | ||
|
||
esbuild( | ||
name = "with_css", | ||
entry_point = "main.ts", | ||
output_css = True, | ||
deps = [ | ||
"external_copied", | ||
":main", | ||
], | ||
) | ||
|
||
jasmine_node_test( | ||
name = "bundle_test", | ||
srcs = ["bundle_test.js"], | ||
data = [ | ||
":default", | ||
":with_css", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { stat } = require("fs"); | ||
const path = require("path"); | ||
|
||
const helper = require(process.env.BAZEL_NODE_RUNFILES_HELPER); | ||
const locationBase = "build_bazel_rules_nodejs/packages/esbuild/test/css/"; | ||
|
||
const cssExpected = helper.resolve(path.join(locationBase, "with_css.css")); | ||
|
||
describe("esbuild css", () => { | ||
it("no css by default", () => { | ||
expect(() => | ||
helper.resolve(path.join(locationBase, "default.css")) | ||
).toThrow(); | ||
}); | ||
|
||
it("css if requested", () => { | ||
stat(cssExpected, (err, stats) => { | ||
expect(err).toBeNull(); | ||
}); | ||
}); | ||
}); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "./external.css"; |