shell-loader icon indicating copy to clipboard operation
shell-loader copied to clipboard

inheriting cwd webpack and maxBuffer to int parse

Open oleg-andreyev opened this issue 5 years ago • 5 comments

  • inheriting from webpack context if it's not defined
  • parseInt for maxBuffer

oleg-andreyev avatar Feb 24 '20 15:02 oleg-andreyev

Hi @oleg-andreyev thank you for your contribution! I'm sorry for the late response. I somehow missed the notification.

Could you explain to me the use case for this change, and why it's necessary to change options inside this plugin rather than passing them in from the Webpack config?

localjo avatar Mar 19 '20 17:03 localjo

@localjo

  1. I'm calling "shell script" which iterates over twig templates and combines then into single file and size of this "prepared" files easily overflow default maxBuffer (1024 * 1024)
  2. cwd is actually inherited from webpack context because to ensure that exec can find this script ❓

Why it's done like so? We're migrating our project from Symfony 3.4 to 4.4 and we used use AsseticBundle (which is not deprecated) but we still use JMSTwigJsBundle.

Our entrypoint looks like this:

require('shell-loader?script=./twig-templates.sh&maxBuffer=4194304!./twig-templates.sh');

oleg-andreyev avatar Mar 19 '20 17:03 oleg-andreyev

I'm not familiar with using require syntax for setting up a Webpack plugin. Can you share some documentation for this approach?

Do you have a Webpack config file? If so, can you try passing maxBuffer from there. In order for the script to be found, you can pass the path into script in the Webpack config too, or configure a shortcut to it in package.json. Would this work in your Webpack config?

module: {
  rules: [
    {
      test: /.*\.twig$/,
      use: [{ loader: 'shell-loader', options: {
        script: './twig-templates.sh',
        maxBuffer: 4194304
      }} ]
    }
  ]
}

(Note: I'm not familiar with Twig or Symfony, so I don't know what the test should be.)

localjo avatar Mar 19 '20 17:03 localjo

@localjo here is the documentation about inline loaders: https://webpack.js.org/concepts/loaders/#inline

oleg-andreyev avatar Mar 20 '20 17:03 oleg-andreyev

Thanks. I'll take a look. I'm feeling a bit under the weather right now, so it might take me awhile to get to this. Any part of your code that you can share with me will help as well. Thanks!

localjo avatar Mar 20 '20 17:03 localjo