Skip to content

webpack is missing?  #1917

@scottwater

Description

@scottwater

I am trying to use purgecss in my production environment (Heroku and Ruby 2.6 if that matters).

On deploy, I am seeing the following output:

" > purgecss-webpack-plugin@1.4.0" has unmet peer dependency "webpack@^4 || ^3"

The deployment succeeds, but it does not look like the purgecss plugin is getting properly executed.

I am using the 3.5.5 version of the web packer gem.

If I read this error message correct, it sounds like it is not finding webpack.

Below are my package.json, environment.js, and production.js.

I am not sure if this is a bug or simply my lack of understanding.

Thanks,
Scott

My package.json

{
  "name": "indie_triage",
  "private": true,
  "dependencies": {
    "@rails/webpacker": "3.5",
    "caniuse-lite": "^1.0.30000697",
    "glob-all": "^3.1.0",
    "jstz": "^2.1.1",
    "purgecss-webpack-plugin": "^1.4.0",
    "tailwindcss": "^0.7.2"
  },
  "devDependencies": {
    "webpack-dev-server": "2.11.2"
  }
}

environment.js

const { environment } = require('@rails/webpacker')
module.exports = environment
process.env.NODE_ENV = process.env.NODE_ENV || 'production'

const environment = require('./environment')

const path = require('path')
const PurgecssPlugin = require('purgecss-webpack-plugin')
const glob = require('glob-all')


// ensure classes with special chars like -mt-1 and md:w-1/3 are included
class TailwindExtractor {
  static extract(content) {
    return content.match(/[A-z0-9-:\/]+/g);
  }
}

environment.plugins.append('PurgecssPlugin', new PurgecssPlugin({
  paths: glob.sync([
    path.join(__dirname, '../../app/javascript/**/*.js'),
    path.join(__dirname, '../../app/views/**/*.erb')
  ]),
  extractors: [ // if using Tailwind
    {
      extractor: TailwindExtractor,
      extensions: ['html', 'js', 'erb']
    }
  ]
}));

module.exports = environment.toWebpackConfig()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions