modify-source-webpack-plugin icon indicating copy to clipboard operation
modify-source-webpack-plugin copied to clipboard

Doesn't run when using Watch

Open bsrobinson opened this issue 1 year ago • 9 comments

I've setup this plugin in my webpack config to re-write sass url's

It works brilliantly when running webpack directly, but if I use set the watch option to true; the re-written urls are lost if any changes are made to the sass files while watching.

Is this expected; can it me made to work?

Thanks, Ben.

bsrobinson avatar May 31 '23 10:05 bsrobinson

Hi Ben. Which version of package do you use?

artembatura avatar May 31 '23 11:05 artembatura

Hi, Only installed recently; my package.json says: "modify-source-webpack-plugin": "^4.0.1",

bsrobinson avatar May 31 '23 11:05 bsrobinson

Can you provide a minimal reproduction example or basic webpack config with your problem?

artembatura avatar May 31 '23 12:05 artembatura

I've stripped the webpack config down to the follow; and still see the issue.

I'm starting the process in the terminal with npx webpack; when this starts "../wwwroot/" is removed from all paths in the sass as expected. When I make a change to an scss file, the watch process rebuilds and the original paths are restored (i.e. the plugin does not execute).

const path = require( 'path' );
const { ModifySourcePlugin, ReplaceOperation } = require('modify-source-webpack-plugin');

module.exports = [{
  watch: true,
  entry: './Styles/Site.scss',
  output: {
    path: path.resolve(__dirname, 'wwwroot/.dist/css/'),
  },
  module: {
    rules: [{
      test: /\.scss$/,
      type: 'asset/resource',
      generator: {
        filename: 'Site.css'
      },
      use: [ 'sass-loader' ]
    }]
  },
  plugins: [
    new ModifySourcePlugin({
      rules: [{
        test: () => true,
        operations: [
          new ReplaceOperation('all', '\'[./]*wwwroot\/', '\'/'),
        ]
      }],
    })
  ]
}];

bsrobinson avatar May 31 '23 13:05 bsrobinson

I have reproduced the problem, thanks. Main reason that cause problem is that we don't attach loader to the same module again. Previously we had to resolve other issues regarding multiple modifications the same module (issue - https://github.com/artembatura/modify-source-webpack-plugin/issues/48#issuecomment-748630893). And it still working good in cases that we are tested (Vue application, for example) and after recompilation in watch mode loader has applied correctly again.

So, I think we are need to do research again how to fix this problem and without unnecessary repeated module modifications. I can do fix for you that removes this limitation and publish under some tag or special version (not release of course) if you need

artembatura avatar May 31 '23 23:05 artembatura

Glad it's not just me!

That would be amazing - thank you!

bsrobinson avatar Jun 01 '23 10:06 bsrobinson

Glad it's not just me!

Probably you misunderstood me, haha. I mean that we're solved problem (in https://github.com/artembatura/modify-source-webpack-plugin/issues/48#issuecomment-748630893) that fixes unnecessary extra modifications to the same module. But this fix has led to the problem that sometimes the loader is not applied (your issue) 😄

artembatura avatar Jun 01 '23 11:06 artembatura

Released 4.1.0 latest with proper fix 🥳. Please check

artembatura avatar Jun 01 '23 13:06 artembatura

Sorry, delayed testing this - looking great - thank you!

ben-wckdrzr avatar Jun 02 '23 22:06 ben-wckdrzr