Skip to content

Commit

Permalink
Merge branch 'master' into refactor-code
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Apr 10, 2021
2 parents 6729a2a + 4d2a8fd commit 03f6517
Show file tree
Hide file tree
Showing 7 changed files with 1,808 additions and 2,294 deletions.
4,010 changes: 1,767 additions & 2,243 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,44 +49,44 @@
}
},
"dependencies": {
"cssnano": "^4.1.10",
"cssnano": "^5.0.0",
"jest-worker": "^26.3.0",
"p-limit": "^3.0.2",
"postcss": "^8.2.9",
"schema-utils": "^3.0.0",
"serialize-javascript": "^5.0.1",
"source-map": "^0.6.1"
},
"devDependencies": {
"@babel/cli": "^7.11.6",
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"@commitlint/cli": "^12.0.1",
"@commitlint/config-conventional": "^12.0.1",
"@babel/cli": "^7.13.14",
"@babel/core": "^7.13.15",
"@babel/preset-env": "^7.13.15",
"@commitlint/cli": "^12.1.1",
"@commitlint/config-conventional": "^12.1.1",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-jest": "^26.3.0",
"clean-css": "^5.1.1",
"copy-webpack-plugin": "^8.0.0",
"clean-css": "^5.1.2",
"copy-webpack-plugin": "^8.1.1",
"cross-env": "^7.0.2",
"css-loader": "^5.0.1",
"css-loader": "^5.2.1",
"csso": "^4.0.3",
"del": "^6.0.0",
"del-cli": "^3.0.1",
"eslint": "^7.9.0",
"eslint": "^7.24.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-import": "^2.22.0",
"husky": "^5.1.3",
"jest": "^26.4.2",
"lint-staged": "^10.4.0",
"memfs": "^3.2.0",
"mini-css-extract-plugin": "^1.3.3",
"memfs": "^3.2.2",
"mini-css-extract-plugin": "^1.4.1",
"npm-run-all": "^4.1.5",
"postcss": "^7.0.32",
"prettier": "^2.1.2",
"sass": "^1.32.8",
"sass-loader": "^11.0.1",
"standard-version": "^9.0.0",
"standard-version": "^9.2.0",
"sugarss": "^3.0.3",
"webpack": "^5.25.0"
"webpack": "^5.31.2"
},
"keywords": [
"cssnano",
Expand Down
15 changes: 0 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as os from 'os';
import { SourceMapConsumer } from 'source-map';
import { validate } from 'schema-utils';
import serialize from 'serialize-javascript';
import * as cssNanoPackageJson from 'cssnano/package.json';
import pLimit from 'p-limit';
import Worker from 'jest-worker';

Expand Down Expand Up @@ -440,20 +439,6 @@ class CssMinimizerPlugin {
);

compiler.hooks.compilation.tap(pluginName, (compilation) => {
const hooks = compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(
compilation
);

const data = serialize({
terser: cssNanoPackageJson.version,
terserOptions: this.options.terserOptions,
});

hooks.chunkHash.tap(pluginName, (chunk, hash) => {
hash.update('CssMinimizerPlugin');
hash.update(data);
});

compilation.hooks.processAssets.tapPromise(
{
name: pluginName,
Expand Down
7 changes: 6 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ async function cssnanoMinify(
};
}

// eslint-disable-next-line global-require
const postcss = require('postcss');
// eslint-disable-next-line global-require
const cssnano = require('cssnano');
const result = await cssnano.process(input, postcssOptions, minimizerOptions);
const result = await postcss([cssnano(minimizerOptions)]).process(
input,
postcssOptions
);

return {
code: result.css,
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/CssMinimizerPlugin.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ exports[`CssMinimizerPlugin should respect the hash options #1: warnings 1`] = `

exports[`CssMinimizerPlugin should run plugin against assets added later by plugins: assets 1`] = `
Object {
"newFile.css": ".a{display:block;color:coral}",
"newFile.css": ".a{color:coral;display:block}",
}
`;

Expand Down Expand Up @@ -104,7 +104,7 @@ exports[`CssMinimizerPlugin should work and do not use memory cache when the "ca

exports[`CssMinimizerPlugin should work and generate real content hash: assets 1`] = `
Object {
"entry.19e4764f9c1d9fe130e2.35ca947c3c124b7cfeb9.f2b99089f2d9520948c5.css": "body{color:red}a{color:#00f}",
"entry.19e4764f9c1d9fe130e2.3a8d5aac970c41cb40b6.4e0651debb6658533ab9.css": "body{color:red}a{color:#00f}",
}
`;

Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/minify-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" and

exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify": assets 1`] = `
Object {
"foo.css": "body{font-weight:700;color:red}body a{text-align:center}
"foo.css": "body{color:red;font-weight:700}body a{text-align:center}
/*# sourceMappingURL=foo.css.map*/",
"foo.css.map": "{\\"version\\":3,\\"sources\\":[\\"webpack:///./sourcemap/bar.scss\\",\\"webpack:///./sourcemap/foo.scss\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SADF,CAEE,OACE,iBAIJ\\",\\"file\\":\\"foo.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}",
"foo.css.map": "{\\"version\\":3,\\"sources\\":[\\"webpack:///./sourcemap/bar.scss\\",\\"webpack:///./sourcemap/foo.scss\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,KCGE,UDFA,eCCF,CAEE,OACE,iBAIJ\\",\\"file\\":\\"foo.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}",
}
`;

Expand Down
32 changes: 16 additions & 16 deletions test/__snapshots__/sourceMap-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Array [

exports[`when applied with "sourceMap" option should work with SourceMapDevToolPlugin plugin): assets 1`] = `
Object {
"dist/entry.css": "body{font-weight:700;color:red}body a{text-align:center}
"dist/entry.css": "body{color:red;font-weight:700}body a{text-align:center}
/*# sourceMappingURL=https://example.com/project/sourcemaps/entry.css.map*/",
"dist/entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
"dist/entry2.css": "body{color:red;font-weight:700}body a{text-align:center}
/*# sourceMappingURL=https://example.com/project/sourcemaps/entry2.css.map*/",
"sourcemaps/entry.css.map": {
"version": 3,
Expand All @@ -39,7 +39,7 @@ Object {
"webpack:///./sourcemap/foo.scss"
],
"names": [],
"mappings": "AAAA,KACE,gBCEA,SADF,CAEE,OACE,iBAIJ",
"mappings": "AAAA,KCGE,UDFA,eCCF,CAEE,OACE,iBAIJ",
"file": "dist/entry.css",
"sourcesContent": [
"body {\\n font-weight: bold;\\n}",
Expand All @@ -54,7 +54,7 @@ Object {
"webpack:///./sourcemap/foo.css"
],
"names": [],
"mappings": "AAAA,KACE,gBCEA,SADF,CAIA,OACE,iBAGF",
"mappings": "AAAA,KCGE,UDFA,eCCF,CAIA,OACE,iBAGF",
"file": "dist/entry2.css",
"sourcesContent": [
"body {\\n font-weight: bold;\\n}",
Expand All @@ -71,7 +71,7 @@ exports[`when applied with "sourceMap" option should work with SourceMapDevToolP

exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: assets 1`] = `
Object {
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
"entry.css": "body{color:red;font-weight:700}body a{text-align:center}
/*# sourceMappingURL=entry.css.map*/",
"entry.css.map": {
"version": 3,
Expand All @@ -80,15 +80,15 @@ Object {
"webpack:///./sourcemap/foo.scss"
],
"names": [],
"mappings": "AAAA,KACE,gBCEA,SADF,CAEE,OACE,iBAIJ",
"mappings": "AAAA,KCGE,UDFA,eCCF,CAEE,OACE,iBAIJ",
"file": "entry.css",
"sourcesContent": [
"body {\\n font-weight: bold;\\n}",
"@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}"
],
"sourceRoot": ""
},
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
"entry2.css": "body{color:red;font-weight:700}body a{text-align:center}
/*# sourceMappingURL=entry2.css.map*/",
"entry2.css.map": {
"version": 3,
Expand All @@ -97,7 +97,7 @@ Object {
"webpack:///./sourcemap/foo.css"
],
"names": [],
"mappings": "AAAA,KACE,gBCEA,SADF,CAIA,OACE,iBAGF",
"mappings": "AAAA,KCGE,UDFA,eCCF,CAIA,OACE,iBAGF",
"file": "entry2.css",
"sourcesContent": [
"body {\\n font-weight: bold;\\n}",
Expand All @@ -114,7 +114,7 @@ exports[`when applied with "sourceMap" option should work with the "devtool" opt

exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: assets 1`] = `
Object {
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
"entry.css": "body{color:red;font-weight:700}body a{text-align:center}
/*# sourceMappingURL=entry.css.map*/",
"entry.css.map": {
"version": 3,
Expand All @@ -123,15 +123,15 @@ Object {
"webpack:///./sourcemap/foo.scss"
],
"names": [],
"mappings": "AAAA,KACE,gBCEA,SADF,CAEE,OACE,iBAIJ",
"mappings": "AAAA,KCGE,UDFA,eCCF,CAEE,OACE,iBAIJ",
"file": "entry.css",
"sourcesContent": [
"body {\\n font-weight: bold;\\n}",
"@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}"
],
"sourceRoot": ""
},
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
"entry2.css": "body{color:red;font-weight:700}body a{text-align:center}
/*# sourceMappingURL=entry2.css.map*/",
"entry2.css.map": {
"version": 3,
Expand All @@ -140,7 +140,7 @@ Object {
"webpack:///./sourcemap/foo.css"
],
"names": [],
"mappings": "AAAA,KACE,gBCEA,SADF,CAIA,OACE,iBAGF",
"mappings": "AAAA,KCGE,UDFA,eCCF,CAIA,OACE,iBAGF",
"file": "entry2.css",
"sourcesContent": [
"body {\\n font-weight: bold;\\n}",
Expand All @@ -157,7 +157,7 @@ exports[`when applied with "sourceMap" option should work with the "devtool" opt

exports[`when applied with "sourceMap" option should work with the "devtool" option: assets 1`] = `
Object {
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
"entry.css": "body{color:red;font-weight:700}body a{text-align:center}
/*# sourceMappingURL=entry.css.map*/",
"entry.css.map": {
"version": 3,
Expand All @@ -166,15 +166,15 @@ Object {
"webpack:///./sourcemap/foo.scss"
],
"names": [],
"mappings": "AAAA,KACE,gBCEA,SADF,CAEE,OACE,iBAIJ",
"mappings": "AAAA,KCGE,UDFA,eCCF,CAEE,OACE,iBAIJ",
"file": "entry.css",
"sourcesContent": [
"body {\\n font-weight: bold;\\n}",
"@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}"
],
"sourceRoot": ""
},
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
"entry2.css": "body{color:red;font-weight:700}body a{text-align:center}
/*# sourceMappingURL=entry2.css.map*/",
"entry2.css.map": {
"version": 3,
Expand All @@ -183,7 +183,7 @@ Object {
"webpack:///./sourcemap/foo.css"
],
"names": [],
"mappings": "AAAA,KACE,gBCEA,SADF,CAIA,OACE,iBAGF",
"mappings": "AAAA,KCGE,UDFA,eCCF,CAIA,OACE,iBAGF",
"file": "entry2.css",
"sourcesContent": [
"body {\\n font-weight: bold;\\n}",
Expand Down

0 comments on commit 03f6517

Please sign in to comment.