Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
roachjc committed Oct 16, 2017
2 parents ab17680 + 91a6dca commit e2203d2
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions plugin/npm-module/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = class MonitorStats {
.map(chunk => chunk.files)
.reduce((arr, el) => arr.concat(el))
.filter(file => /\.js($|\?)/.test(file))
.filter(file => compilation.assets[file])
.forEach((file) => {
const source = compilation.assets[file].source();
const minified = source.split(/\r\n|\r|\n/).length < 25;
Expand All @@ -45,12 +46,13 @@ module.exports = class MonitorStats {
cb();
});

// // CHECK UNPURE CSS
// CHECK UNPURE CSS
compiler.plugin('emit', (compilation, cb) => {
const css = compilation.chunks
.map(chunk => chunk.files)
.reduce((arr, el) => arr.concat(el))
.filter(file => /\.css($|\?)/.test(file))
.filter(file => compilation.assets[file])
.reduce((concat, file) => {
const sourceCSS = compilation.assets[file].source();
return concat += sourceCSS;
Expand All @@ -60,24 +62,30 @@ module.exports = class MonitorStats {
.map(chunk => chunk.files)
.reduce((arr, el) => arr.concat(el))
.filter(file => /\.js($|\?)/.test(file))
.filter(file => compilation.assets[file])
.reduce((concat, file) => {
const sourceJs = compilation.assets[file].source();
return concat += sourceJs;
}, '');

const purified = purifycss(js, css, { minify: false });
const purified = purifycss(js || '', css || '', { minify: false });
pureSize = purified.length;
cb();
});

// CHECK IF TARGET DIRECTORY EXISTS...
if (!fs.existsSync(target)) {
const targetDir = path.dirname(target)
if (!fs.existsSync(targetDir)) {
// ...make directory if it does not
fs.mkdirSync(path.resolve(__dirname, '../..', 'monitor'));
data = [];
} else {
fs.mkdirSync(targetDir);
}

// CHECK IF TARGET FILE EXISTS...
if (fs.existsSync(target)) {
// ...get existing data if it does
data = JSON.parse(fs.readFileSync(target, { encoding: 'utf8' }));
} else {
data = [];
}

compiler.plugin('done', (stats) => {
Expand Down

0 comments on commit e2203d2

Please sign in to comment.