Skip to content

Commit

Permalink
Merge pull request #29 from FullHuman/webpack-4
Browse files Browse the repository at this point in the history
Webpack 4
  • Loading branch information
Ffloriel committed Oct 30, 2019
1 parent 84f567d commit efebfa5
Show file tree
Hide file tree
Showing 23 changed files with 201 additions and 27,375 deletions.
4 changes: 1 addition & 3 deletions packages/purgecss-webpack-plugin/.travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
language: node_js
node_js:
- "7"
before_install:
- npm i -g npm@5.3.0
- "8"
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exports[`Webpack Integration Tests path-and-whitelist-functions 1`] = `
md\\\\:w-2\\\\/3 {
color: red;
}
"
`;

Expand All @@ -31,6 +32,7 @@ exports[`Webpack Integration Tests simple 1`] = `
md\\\\:w-2\\\\/3 {
color: red;
}
"
`;

Expand All @@ -39,18 +41,19 @@ exports[`Webpack Integration Tests simple-with-exclusion 1`] = `
color: red;
}
.unused {
color: blue;
}
.whitelisted {
color: green;
}
md\\\\:w-2\\\\/3 {
color: red;
}
"
`;
exports[`Webpack Integration Tests simple-with-exclusion 2`] = `
".legacy-unused-class {
.legacy-unused-class {
color: red;
}
Expand All @@ -61,5 +64,6 @@ exports[`Webpack Integration Tests simple-with-exclusion 2`] = `
.hello {
color: red;
}
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
md\:w-2\/3 {
color: red;
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path')
const glob = require('glob')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const PurgecssPlugin = require('../../../src/').default

class CustomExtractor {
Expand All @@ -14,19 +14,32 @@ const PATHS = {
}

module.exports = {
mode: 'development',
entry: './src/index.js',
optimization: {
splitChunks: {
cacheGroups: {
styles: {
name: 'styles',
test: /\.css$/,
chunks: 'all',
enforce: true
}
}
}
},
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
use: 'css-loader?sourceMap'
})
use: [MiniCssExtractPlugin.loader, 'css-loader']
}
]
},
plugins: [
new ExtractTextPlugin('style.css'),
new MiniCssExtractPlugin({
filename: '[name].css'
}),
new PurgecssPlugin({
paths: () => glob.sync(`${PATHS.src}/*`),
whitelist: () => ['whitelisted'],
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.hello {
color: red;
}

.unused {
color: blue;
}

.whitelisted {
color: green;
}

md\:w-2\/3 {
color: red;
}

.legacy-unused-class {
color: red;
}

.unused-too {
color: blue;
}

.hello {
color: red;
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path')
const glob = require('glob')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const PurgecssPlugin = require('../../../src/').default

class CustomExtractor {
Expand All @@ -14,22 +14,35 @@ const PATHS = {
}

module.exports = {
mode: 'development',
entry: {
bundle: './src/index.js',
legacy: './src/legacy.js'
},
optimization: {
splitChunks: {
cacheGroups: {
styles: {
name: 'styles',
test: /\.css$/,
chunks: 'all',
enforce: true
}
}
}
},
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
use: 'css-loader?sourceMap'
})
use: [MiniCssExtractPlugin.loader, 'css-loader']
}
]
},
plugins: [
new ExtractTextPlugin('[name].css?[hash]'),
new MiniCssExtractPlugin({
filename: '[name].css'
}),
new PurgecssPlugin({
paths: glob.sync(`${PATHS.src}/*`),
styleExtensions: ['.css'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
md\:w-2\/3 {
color: red;
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path')
const glob = require('glob')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const PurgecssPlugin = require('../../../src/').default

class CustomExtractor {
Expand All @@ -14,19 +14,32 @@ const PATHS = {
}

module.exports = {
mode: 'development',
optimization: {
splitChunks: {
cacheGroups: {
styles: {
name: 'styles',
test: /\.css$/,
chunks: 'all',
enforce: true
}
}
}
},
entry: './src/index.js',
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
use: 'css-loader?sourceMap'
})
use: [MiniCssExtractPlugin.loader, 'css-loader']
}
]
},
plugins: [
new ExtractTextPlugin('style.css'),
new MiniCssExtractPlugin({
filename: '[name].css'
}),
new PurgecssPlugin({
paths: glob.sync(`${PATHS.src}/*`),
whitelist: ['whitelisted'],
Expand Down
8 changes: 4 additions & 4 deletions packages/purgecss-webpack-plugin/__tests__/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ describe('Search files', () => {
})

it('returns matches based on extension', () => {
chunk.modules = ['foobar.txt', 'barbar.css']
chunk.modulesIterable = ['foobar.txt', 'barbar.css']
const extensions = ['.txt']
const matches = ['foobar.txt']

expect(files(chunk, extensions)).toEqual(matches)
})

it('does not fail with missing modules', () => {
chunk.modules = ['foobar.txt', '', 'barbar.css']
chunk.modulesIterable = ['foobar.txt', '', 'barbar.css']
const extensions = ['.txt']
const matches = ['foobar.txt']

expect(files(chunk, extensions)).toEqual(matches)
})

it('returns matches based on extension with a customized getter', () => {
chunk.modules = [
chunk.modulesIterable = [
{
resource: 'foobar.txt'
},
Expand All @@ -70,7 +70,7 @@ describe('Search files', () => {
})

it('does not fail with missing modules when a getter fails', () => {
chunk.modules = [
chunk.modulesIterable = [
{
resource: 'foobar.txt'
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fs from 'fs'
import path from 'path'
import webpack from 'webpack'
import ExtractPlugin from 'extract-text-webpack-plugin'

const cases = process.env.CASES
? process.env.CASES.split(',')
Expand All @@ -20,11 +19,6 @@ describe('Webpack Integration Tests', () => {
}
options.context = testDirectory
if (!options.module) options.module = {}
if (!options.module.loaders) {
options.module.loaders = [
{ test: /\.txt$/, loader: ExtractPlugin.extract('raw-loader') }
]
}
if (!options.output) options.output = { filename: '[name].js' }
if (!options.output.path) options.output.path = outputDirectory
if (process.env.CASES) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(window.webpackJsonp=window.webpackJsonp||[]).push([[0],{2:function(n,w,o){}}]);
Loading

0 comments on commit efebfa5

Please sign in to comment.