Skip to content

Commit

Permalink
perf(css): webpack purge css
Browse files Browse the repository at this point in the history
  • Loading branch information
shadow81627 committed Dec 17, 2019
1 parent 30df058 commit 3f5ff8e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
29 changes: 24 additions & 5 deletions nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const path = require('path');
const PurgecssPlugin = require('purgecss-webpack-plugin');
const glob = require('glob-all');

const purgecss = require('@fullhuman/postcss-purgecss');
const pkg = require('./package');

Expand Down Expand Up @@ -192,11 +196,11 @@ module.exports = {
langDir: 'lang/',
},

// optimizedImages: {
// mozjpeg: {
// quality: 70,
// },
// },
optimizedImages: {
mozjpeg: {
quality: 50,
},
},

// storyblok: {},

Expand Down Expand Up @@ -243,6 +247,21 @@ module.exports = {
exclude: /(node_modules)/,
});
}

if (!ctx.isDev) {
// Remove unused CSS using PurgeCSS. See https://github.com/FullHuman/purgecss
// for more information about PurgeCSS.
config.plugins.push(
new PurgecssPlugin({
paths: glob.sync([
path.join(__dirname, './pages/**/*.vue'),
path.join(__dirname, './layouts/**/*.vue'),
path.join(__dirname, './components/**/*.vue'),
]),
whitelist: ['html', 'body'],
}),
);
}
},
},

Expand Down
37 changes: 37 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"eslint-config-prettier": "6.7.0",
"eslint-plugin-nuxt": "0.5.0",
"eslint-plugin-prettier": "3.1.2",
"glob-all": "3.1.0",
"husky": "3.1.0",
"imagemin-gifsicle": "6.0.1",
"imagemin-mozjpeg": "8.0.0",
Expand All @@ -80,6 +81,7 @@
"lqip-loader": "2.2.0",
"nodemon": "2.0.2",
"prettier": "1.19.1",
"purgecss-webpack-plugin": "1.6.0",
"require-extension-hooks": "0.3.3",
"require-extension-hooks-babel": "1.0.0",
"require-extension-hooks-vue": "3.0.0",
Expand Down

1 comment on commit 3f5ff8e

@vercel
Copy link

@vercel vercel bot commented on 3f5ff8e Dec 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.