Coder Social home page Coder Social logo

eels / next-purge-css-modules Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 2.0 58 KB

Easily remove unused css-module code in your Next.js application

Home Page: https://www.npmjs.com/package/next-purge-css-modules

License: MIT License

Shell 0.94% TypeScript 99.06%
nextjs css-modules nextjs-plugin css scss purgecss

next-purge-css-modules's People

Contributors

dependabot[bot] avatar eels avatar filiphsps avatar gianpaj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

gianpaj filiphsps

next-purge-css-modules's Issues

officially support nextjs 13+

I get this warning when installing with pnpm

 WARN  Issues with peer dependencies found
next-purge-css-modules 1.1.0
  └── ✕ unmet peer next@">= 11.0.0 < 13.0.0": found 13.4.2
next 13.4.2

Support for Next 14 ?

Expected Behavior

  • I took a screenshot of the CSS loaded before using next-purge-css-modules
  • I installed and added the dependency to my Next config:
...
const bundleAnalyzer = require('@next/bundle-analyzer')
const withBundleAnalyzer = bundleAnalyzer({
  enabled: process.env.ANALYZE_BUNDLE === 'true',
})

const withPurgeCSSModules = require('next-purge-css-modules')
const purgeConfig = {
  content: path.join(__dirname, 'src/**/*.{js,jsx,ts,tsx}'),
  enableDevPurge: true,
  safelist: ['body', 'html'],
};

module.export = withPurgeCSSModules(purgeConfig, withBundleAnalyzer({
  basePath: '',
  rewrites: () => [
    ...
  • I redeploy/rebuild the app with the pushed changes
  • On the Network tab of chrome dev tools, I should see smaller CSS requests
  • The coverage tab of chrome dev tools should not list a lot of unused css

Actual Behavior

  • On the Network tab of chrome dev tools the CSS requests have exactly the same size
  • The coverage tab of chrome dev tools list a lot of unused css
  • The content of folder .next/static/css/ is exactly the same before and after adding next-purge-css-modules

Specifications

I am using TypeScript and a css-in-js library ([email protected]) so basically everything has .ts or .tsx file extension, so `purgeConfig.content' seems fine.

Also I already have some webpack config !

  webpack(config, { dev, isServer }) {
    if (dev && !isServer) {
      const originalEntry = config.entry
      config.entry = async () => {
        const wdrPath = path.resolve(getDirName(), './scripts/wdyr.ts')
        const entries = await originalEntry()

        if (entries['main.js'] && !entries['main.js'].includes(wdrPath)) {
          entries['main.js'].push(wdrPath)
        }
        return entries
      }
    }
    // see https://github.com/Automattic/mongoose/issues/13402#issuecomment-1548826056
    Object.assign(config.resolve.alias, {
      '@mongodb-js/zstd': false,
      '@aws-sdk/credential-providers': false,
      'snappy': false,
      'aws4': false,
      'mongodb-client-encryption': false,
      'kerberos': false,
      'supports-color': false
    })
    return config
  },

Should remove unused css that is assigned to unused variables

Expected Behavior

  • Should remove unused css classes, even if they are assigned to an unused variable

Actual Behavior

  • Doesn't remove CSS, nor the variable

Steps to Reproduce the Problem

  1. import a module.css file
  2. assign css class from that module to a variable
  3. don't ever use that variable again

CodeSandbox Link / Code Snippets

import styles from './Grid.module.css';

const fooStyle = styles.foo; // unused

export const MyComponent = () => <div></div>;

As soon as you use the exported component, the css will be bundled

Specifications

  • Version: 1.1.0
  • Platform: Node 18.2.0, Windows 11, next 12.3.1
  • Subsystem:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.