webpack/test/configCases/plugins/uglifyjs-plugin/index.js

66 lines
2.4 KiB
JavaScript
Raw Normal View History

it("should contain no comments in out chunk", () => {
const fs = require("fs");
const source = fs.readFileSync(__filename, "utf-8");
expect(source).not.toMatch(/[^\"]comment should be stripped test\.1[^\"]/);
expect(source).not.toMatch(/[^\"]comment should be stripped test\.2[^\"]/);
expect(source).not.toMatch(/[^\"]comment should be stripped test\.3[^\"]/);
});
it("should contain comments in vendors chunk", function() {
const fs = require("fs");
const path = require("path");
const source = fs.readFileSync(path.join(__dirname, "vendors.js"), "utf-8");
expect(source).toMatch("comment should not be stripped vendors.1");
expect(source).toMatch("// comment should not be stripped vendors.2");
expect(source).toMatch(" * comment should not be stripped vendors.3");
});
UglifyJsPlugin: extract comments to separate file License comments use up a lot of space, especially when using many small libraries with large license blocks. With this addition, you can extract all license comments to a separate file and remove them from the bundle files. A small banner points to the file containing all license information such that the user can find it if needed. We add a new option extractComments to the UglifyJsPlugin. It can be omitted, then the behavior does not change, or it can be: - true: All comments that normally would be preserved by the comments option will be moved to a separate file. If the original file is named foo.js, then the comments will be stored to foo.js.LICENSE - regular expression (given as RegExp or string) or a function (astNode, comment) -> boolean: All comments that match the given expression (resp. are evaluated to true by the function) will be extracted to the separate file. The comments option specifies whether the comment will be preserved, i.e. it is possible to preserve some comments (e.g. annotations) while extracting others or even preserving comments that have been extracted. - an object consisting of the following keys, all optional: - condition: regular expression or function (see previous point) - file: The file where the extracted comments will be stored. Can be either a string (filename) or function (string) -> string which will be given the original filename. Default is to append the suffix .LICENSE to the original filename. - banner: The banner text that points to the extracted file and will be added on top of the original file. will be added to the original file. Can be false (no banner), a string, or a function (string) -> string that will be called with the filename where extracted comments have been stored. Will be wrapped into comment. Default: /*! For license information please see foo.js.LICENSE */
2017-01-30 07:43:09 +08:00
it("should extract comments to separate file", function() {
const fs = require("fs");
const path = require("path");
const source = fs.readFileSync(path.join(__dirname, "extract.js.LICENSE"), "utf-8");
expect(source).toMatch("comment should be extracted extract-test.1");
expect(source).not.toMatch("comment should be stripped extract-test.2");
expect(source).toMatch("comment should be extracted extract-test.3");
expect(source).not.toMatch("comment should be stripped extract-test.4");
UglifyJsPlugin: extract comments to separate file License comments use up a lot of space, especially when using many small libraries with large license blocks. With this addition, you can extract all license comments to a separate file and remove them from the bundle files. A small banner points to the file containing all license information such that the user can find it if needed. We add a new option extractComments to the UglifyJsPlugin. It can be omitted, then the behavior does not change, or it can be: - true: All comments that normally would be preserved by the comments option will be moved to a separate file. If the original file is named foo.js, then the comments will be stored to foo.js.LICENSE - regular expression (given as RegExp or string) or a function (astNode, comment) -> boolean: All comments that match the given expression (resp. are evaluated to true by the function) will be extracted to the separate file. The comments option specifies whether the comment will be preserved, i.e. it is possible to preserve some comments (e.g. annotations) while extracting others or even preserving comments that have been extracted. - an object consisting of the following keys, all optional: - condition: regular expression or function (see previous point) - file: The file where the extracted comments will be stored. Can be either a string (filename) or function (string) -> string which will be given the original filename. Default is to append the suffix .LICENSE to the original filename. - banner: The banner text that points to the extracted file and will be added on top of the original file. will be added to the original file. Can be false (no banner), a string, or a function (string) -> string that will be called with the filename where extracted comments have been stored. Will be wrapped into comment. Default: /*! For license information please see foo.js.LICENSE */
2017-01-30 07:43:09 +08:00
});
it("should remove extracted comments and insert a banner", function() {
const fs = require("fs");
const path = require("path");
const source = fs.readFileSync(path.join(__dirname, "extract.js"), "utf-8");
expect(source).not.toMatch("comment should be extracted extract-test.1");
expect(source).not.toMatch("comment should be stripped extract-test.2");
expect(source).not.toMatch("comment should be extracted extract-test.3");
expect(source).not.toMatch("comment should be stripped extract-test.4");
expect(source).toMatch("/*! For license information please see extract.js.LICENSE */");
UglifyJsPlugin: extract comments to separate file License comments use up a lot of space, especially when using many small libraries with large license blocks. With this addition, you can extract all license comments to a separate file and remove them from the bundle files. A small banner points to the file containing all license information such that the user can find it if needed. We add a new option extractComments to the UglifyJsPlugin. It can be omitted, then the behavior does not change, or it can be: - true: All comments that normally would be preserved by the comments option will be moved to a separate file. If the original file is named foo.js, then the comments will be stored to foo.js.LICENSE - regular expression (given as RegExp or string) or a function (astNode, comment) -> boolean: All comments that match the given expression (resp. are evaluated to true by the function) will be extracted to the separate file. The comments option specifies whether the comment will be preserved, i.e. it is possible to preserve some comments (e.g. annotations) while extracting others or even preserving comments that have been extracted. - an object consisting of the following keys, all optional: - condition: regular expression or function (see previous point) - file: The file where the extracted comments will be stored. Can be either a string (filename) or function (string) -> string which will be given the original filename. Default is to append the suffix .LICENSE to the original filename. - banner: The banner text that points to the extracted file and will be added on top of the original file. will be added to the original file. Can be false (no banner), a string, or a function (string) -> string that will be called with the filename where extracted comments have been stored. Will be wrapped into comment. Default: /*! For license information please see foo.js.LICENSE */
2017-01-30 07:43:09 +08:00
});
it("should pass mangle options", function() {
const fs = require("fs");
const path = require("path");
const source = fs.readFileSync(path.join(__dirname, "ie8.js"), "utf-8");
expect(source).toMatch("t.exports=function(t){return function(n){try{t()}catch(t){n(t)}}}");
});
it("should pass compress options", function() {
const fs = require("fs");
const path = require("path");
const source = fs.readFileSync(path.join(__dirname, "compress.js"), "utf-8");
expect(source).toMatch("o.exports=function(){console.log(4),console.log(6),console.log(4),console.log(7)}");
});
require.include("./test.js");