Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assess to webpack compilation object in postcss config context #354

Closed
kisenka opened this issue Apr 6, 2018 · 3 comments · Fixed by #443
Closed

Assess to webpack compilation object in postcss config context #354

kisenka opened this issue Apr 6, 2018 · 3 comments · Fixed by #443

Comments

@kisenka
Copy link
Contributor

kisenka commented Apr 6, 2018

I writing postcss plugin which produce extra asset (svg sprite) and need ability to write this asset to webpack's output file system. In 0.x versions of this loader it was feature when you can access loader object itself (webpack context property of postcss config). Using this, postcss plugins for instance can write assets directly to webpack compilation object, but it was removed. I suggest following:

  • Postcss plugin generate message with new type "asset"
  • If loader find such message it creates file in webpack compilation

Example

some-postcss-plugin.js

function plugin() {
  return (tree, result) => {

    // do stuff...

    result.messages.push({
      type: 'asset',
      file: 'sprite.svg',
      content: '<svg>...</svg>',
      plugin
    });
  }
}

postcss-loader

if (msg.type === 'asset' && msg.content && msg.file) {
  this._compilation.assets[msg.file] = {
    source() { return msg.content; },
    size() { return msg.content.length; }
  };
}

I will be glad to make PR with this feature!

@alexander-akait
Copy link
Member

@michael-ciniawsky looks like we break plugins which emit assets. I think we should return this behaviour

@michael-ciniawsky
Copy link
Member

I like the idea, but need more info about exact requirements here. @kisenka could you share a small demo project ?

⚠️ this._compilation is also deprecated so we need to ensure that e.g this.emitFile or adding the asset directly to module.assets works/is sufficient

@alexander-akait
Copy link
Member

@kisenka friendly ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants