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

Doesn't run when using Watch #87

Open
bsrobinson opened this issue May 31, 2023 · 9 comments
Open

Doesn't run when using Watch #87

bsrobinson opened this issue May 31, 2023 · 9 comments

Comments

@bsrobinson
Copy link

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.

@artembatura
Copy link
Owner

Hi Ben. Which version of package do you use?

@bsrobinson
Copy link
Author

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

@artembatura
Copy link
Owner

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

@bsrobinson
Copy link
Author

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\/', '\'/'),
        ]
      }],
    })
  ]
}];

@artembatura
Copy link
Owner

artembatura commented May 31, 2023

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 - #48 (comment)). 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

@bsrobinson
Copy link
Author

Glad it's not just me!

That would be amazing - thank you!

@artembatura
Copy link
Owner

artembatura commented Jun 1, 2023

Glad it's not just me!

Probably you misunderstood me, haha. I mean that we're solved problem (in #48 (comment)) 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
Copy link
Owner

Released 4.1.0 latest with proper fix 🥳. Please check

artembatura added a commit that referenced this issue Jun 1, 2023
@ben-wckdrzr
Copy link

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

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

No branches or pull requests

3 participants