Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,8 @@ class TerserPlugin {
);
}

if (output.code) {
// Custom functions can return `undefined` or `null`
if (typeof output.code !== "undefined" && output.code !== null) {
let shebang;

if (
Expand Down
14 changes: 14 additions & 0 deletions test/TerserPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,20 @@ describe("TerserPlugin", () => {
}
});

it("should work with empty files", async () => {
const compiler = getCompiler({
entry: path.resolve(__dirname, "fixtures/empty.js"),
});

new TerserPlugin().apply(compiler);

const stats = await compile(compiler);

expect(readsAssets(compiler, stats)).toMatchSnapshot("assets");
expect(getErrors(stats)).toMatchSnapshot("errors");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
});

it("should work when some of assets do not contain source maps", async () => {
const compiler = getCompiler({
devtool: "source-map",
Expand Down
30 changes: 14 additions & 16 deletions test/__snapshots__/TerserPlugin.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,16 @@ exports[`TerserPlugin should work with child compilation: errors 1`] = `Array []

exports[`TerserPlugin should work with child compilation: warnings 1`] = `Array []`;

exports[`TerserPlugin should work with empty files: assets 1`] = `
Object {
"main.js": "",
}
`;

exports[`TerserPlugin should work with empty files: errors 1`] = `Array []`;

exports[`TerserPlugin should work with empty files: warnings 1`] = `Array []`;

exports[`TerserPlugin should work with multi compiler mode with source maps: assets 1`] = `
Object {
"main-1.js": "(()=>{var __webpack_modules__={921:module=>{eval(\\"{// foo\\\\n/* @preserve*/\\\\n// bar\\\\nconst a = (/* unused pure expression or super */ null && (2 + 2));\\\\n\\\\nmodule.exports = function Foo() {\\\\n const b = 2 + 2;\\\\n console.log(b + 1 + 2);\\\\n};\\\\n\\\\n\\\\n//# sourceURL=webpack://terser-webpack-plugin/./test/fixtures/entry.js?\\\\n}\\")}},__webpack_module_cache__={};function __webpack_require__(e){var _=__webpack_module_cache__[e];if(void 0!==_)return _.exports;var r=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](r,r.exports,__webpack_require__),r.exports}var __webpack_exports__=__webpack_require__(921)})();",
Expand Down Expand Up @@ -3377,14 +3387,8 @@ exports[`TerserPlugin should work, extract comments in one file and use memory c

exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in not parallel mode: assets 1`] = `
Object {
"one.js": "/******/ (() => { // webpackBootstrap

/******/ })()
;",
"two.js": "/******/ (() => { // webpackBootstrap

/******/ })()
;",
"one.js": "",
"two.js": "",
}
`;

Expand All @@ -3406,14 +3410,8 @@ exports[`TerserPlugin should write stdout and stderr of workers to stdout and st

exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: assets 1`] = `
Object {
"one.js": "/******/ (() => { // webpackBootstrap

/******/ })()
;",
"two.js": "/******/ (() => { // webpackBootstrap

/******/ })()
;",
"one.js": "",
"two.js": "",
}
`;

Expand Down