Skip to content

Commit

Permalink
feat: upgrade esbuild to 0.12.19 and add CSS source map support (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored Aug 10, 2021
1 parent 14986cc commit 029f17f
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 297 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"webpack": "^4.40.0 || ^5.0.0"
},
"dependencies": {
"esbuild": "^0.12.17",
"esbuild": "^0.12.19",
"joycon": "^3.0.1",
"json5": "^2.2.0",
"loader-utils": "^2.0.0",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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

22 changes: 10 additions & 12 deletions src/minify-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,16 @@ class ESBuildMinifyPlugin {
asset.name,
(
sourcemap
// CSS source-maps not supported yet https://github.com/evanw/esbuild/issues/519
&& !assetIsCss
)
? new SourceMapSource(
result.code,
asset.name,
result.map as any,
sourceAsString,
map,
true,
)
: new RawSource(result.code),
? new SourceMapSource(
result.code,
asset.name,
result.map as any,
sourceAsString,
map,
true,
)
: new RawSource(result.code)
),
{
...asset.info,
minimized: true,
Expand Down
230 changes: 102 additions & 128 deletions test/__snapshots__/loader.test.ts.snap

Large diffs are not rendered by default.

296 changes: 151 additions & 145 deletions test/__snapshots__/minify.test.ts.snap

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ const js = {
})();
export const esnext = (() => {
class PrivateStatic {
static #x() {}
}
return [
class { x = 2; },
class { static x = 1; },
class { #x() {} },
class { #x },
class { static #x },
class { static #x() {} },
1_000_000_000,
];
})();
Expand Down
11 changes: 7 additions & 4 deletions test/minify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,6 @@ describe.each([
expect(file.content.trim()).toMatch(/\s{2,}/);
});

// Esbuild currently doesn't support CSS source-maps but checking to make sure no errors
// https://github.com/evanw/esbuild/issues/519
test('minify w/ source-map', async () => {
const stats = await build(webpack, fixtures.css, (config) => {
config.devtool = 'source-map';
Expand All @@ -457,8 +455,13 @@ describe.each([
config.plugins.push(new MiniCssExtractPlugin());
});

const file = getFile(stats, '/dist/index.css');
expect(file.content.trim()).not.toMatch(/\s{2,}/);
const cssFile = getFile(stats, '/dist/index.css');
const css = cssFile.content.trim().split('\n');
expect(css[0]).not.toMatch(/\s{2,}/);
expect(css[2]).toMatch(/sourceMappingURL/);

const sourcemapFile = getFile(stats, '/dist/index.css.map');
expect(sourcemapFile.content).toMatch(/styles\.css/);
});
});
});
Expand Down

0 comments on commit 029f17f

Please sign in to comment.