question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

other plugin invoke twice

See original GitHub issue
const postcss = require( 'postcss' )
const modules = require( 'postcss-modules' )

let testPlugin = postcss.plugin( 'test-plugin-1', () => {
    return () => {
        console.log( 'test-plugin-1 running' )
    }
} )

let testPlugin2 = postcss.plugin( 'test-plugin-2', () => {
    return () => {
        console.log( 'test-plugin-2 running' )
    }
} )

postcss( [
    modules( {
        getJSON( _, json ) {
        }
    } ),
    testPlugin(),
    testPlugin2()
] )
    .process( `
    .title {
        color: green;
    }` )
    .then( () => {
    } )

if you run this code, that two plugins were running twice. Did i use this plugin in a wrong way?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
EECOLORcommented, Feb 16, 2019

@peter-mouland I recommend you move away from this module as it is not properly maintained. I have opened several pull requests and issues (to upgrade the postcss dependency) in October, but they are still open.

Both our our webpack css loader and the defaul css loader have adopted another strategy of supporting css modules.

Incidentally, this other approach does not involve the composition plugin.

1reaction
EECOLORcommented, Sep 19, 2017

No you did not. I don’t know why, but this plugin executes postcss with all other plugins: https://github.com/css-modules/postcss-modules/blob/master/src/index.js#L75

The simple fix is:

const plugins = [
  require('postcss-plugin-composition', [
      // plugins that need to run on each individual file (import, modules, etc.)
  ]),
  // plugins that need to run on the result (once)
]

Please be aware of: https://github.com/btd/postcss-plugin-composition/issues/1

A copy without this problem:

const postcss = require('postcss')

module.exports = postcss.plugin('postcss-plugin-composition', plugins => {
  if(!Array.isArray(plugins)) throw new Error('`options` for postcss-plugin-composition must be array of plugins')

  return (root, { opts, messages }) => 
    postcss(plugins)
      .process(root, opts)
      .then(({ messages: m }) => { messages.push.apply(messages, m) })
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

other plugin invoke twice · Issue #70 - GitHub
if you run this code, that two plugins were running twice. Did i use this plugin in a wrong way? The text was...
Read more >
Maven: run plugin twice during a phase, interleaved with ...
In this case we would need a kind of merge attribute on the execution element or have a different behavior by default (that...
Read more >
Plugin executed twice? - Microsoft Dynamics CRM Forum ...
The plugin should not be executing twice. Do you have any other plugins that are showing this behavior? Was the plugin registered in...
Read more >
WordPress plugin executing code twice
I did a test to confirm it, so here is the output of the time: <date=12:36:34 am> <date=12:36:41am> . When I open my...
Read more >
How to run a plugin twice in one project? - Gradle Forums
I would like to run it twice with different direcotries. When you have one type of less css it is simple, just implement...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found