Skip to content

Commit df646ba

Browse files
committed
Replacing html-critical-webpack-plugin package with critical-css-webpack-plugin
Adding lodash as dependency so we can use "merge" Updating README.md
1 parent 0e737e2 commit df646ba

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,21 @@ mix
3030
enabled: mix.inProduction(),
3131
paths: {
3232
base: 'https://url-of-where-criticalcss-is-extracted.com/',
33-
templates: './where-critical-css-file-needs-to-be-written/',
33+
templates: './css/critical', //Where css files need to be written, all these paths are relative to /public
34+
//So the example path here will be public/css/critical
3435
suffix: '_critical.min'
3536
},
3637
urls: [
3738
{ url: 'blog', template: 'blog' },
3839
],
40+
//Now using https://github.com/addyosmani/critical v4.0.1
3941
options: {
40-
minify: true,
42+
//It's important to note here you should NOT set inline:true, this will break the whole system.
43+
width:411,
44+
height:823,
45+
penthouse:{
46+
timeout:1200000
47+
}
4148
},
4249
});
4350

index.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const mix = require('laravel-mix');
2+
const merge = require('lodash/merge');
23

34
class Critical {
45
constructor() {
@@ -7,10 +8,10 @@ class Critical {
78

89
dependencies() {
910
this.requiresReload = `
10-
HTML Webpack critical has been installed. Please run "npm run dev" again.
11+
Critical-Css-Webpack-Plugin has been installed. Please run "npm run dev" again.
1112
`;
1213

13-
return ['html-critical-webpack-plugin'];
14+
return ['critical-css-webpack-plugin'];
1415
}
1516

1617
register(config) {
@@ -20,11 +21,13 @@ class Critical {
2021
);
2122
}
2223

23-
const critical = Object.assign({
24+
const critical = merge({
2425
enabled: mix.inProduction(),
2526
paths: {},
2627
urls: [],
27-
options: {},
28+
options: {
29+
inline:false
30+
},
2831
}, config);
2932

3033
if (critical.paths.suffix == null) critical.paths.suffix = '_critical.min';
@@ -34,14 +37,16 @@ class Critical {
3437

3538
webpackPlugins() {
3639
if (this.criticals.map((e) => e.enabled).some(Boolean)) {
37-
const HtmlCritical = require('html-critical-webpack-plugin');
40+
41+
const CriticalCssPlugin = require("critical-css-webpack-plugin");
42+
3843
const plugins = [];
3944

4045
this.criticals.forEach((critical) => {
4146

4247
critical.enabled && critical.urls.forEach((template) => {
4348
const criticalSrc = critical.paths.base + template.url;
44-
const criticalDest = `${critical.paths.templates + template.template + critical.paths.suffix }.css`;
49+
const criticalDest = `${critical.paths.templates + template.template + critical.paths.suffix}.css`;
4550

4651
if (criticalSrc.indexOf('amp_') !== -1) {
4752

@@ -50,9 +55,9 @@ class Critical {
5055

5156
}
5257

53-
plugins.push(new HtmlCritical(Object.assign({
58+
plugins.push(new CriticalCssPlugin(Object.assign({
5459
src: criticalSrc,
55-
dest: criticalDest,
60+
target: criticalDest,
5661
}, critical.options)));
5762
});
5863

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
},
2525
"homepage": "https://github.com/dadamotion/laravel-mix-criticalcss#readme",
2626
"dependencies": {
27-
"html-critical-webpack-plugin": "^2.1.0"
27+
"critical-css-webpack-plugin": "^3.0.0",
28+
"lodash": "^4.17.21"
2829
},
2930
"peerDependencies": {
3031
"laravel-mix": "^4.0.0 || ^5.0.0 || ^6.0.0"

0 commit comments

Comments
 (0)