Giter Club home page Giter Club logo

Comments (10)

Va1 avatar Va1 commented on June 12, 2024 3

as i mentioned in the previous comment, string-replace-loader is a loader on contrast to DefinePlugin being a plugin. this means, that it can be used for specific files via regex (as loaders are defined with test property) and, what's more important, in specific positions in the loader chain (before loader A does it's job, but over results loader B has produced, if defined between em).

this, i believe, makes both just different tools, use-cases of which intersect but are not equal by any means. which invalidates the "why 3rd party loader" question, in my opinion. examples defined in readme are plain variable replacement ones, but this does not deny the point i wrote above, as well as does not mean that more complex examples should be added to justify its existence (or does it? and does this module lack examples overall?).

what may be a justified thing to do is to reference the DefinePlugin in a form like "yo btw, if what you're doing is a simple & global variable replacement, you may be able to achieve it via DefinePlugin, read more here". but the emphasis on examples seems a bit over the top to me (i might be wrong tho).

from string-replace-loader.

pietia avatar pietia commented on June 12, 2024 1

I've refactored my project so that i can use DefinePlugin , so - case closed.

from string-replace-loader.

pietia avatar pietia commented on June 12, 2024

@fregante Isn't that DefinePlugin can operate only on entry points while string-replace-loader can update any file ?

from string-replace-loader.

fregante avatar fregante commented on June 12, 2024

DefinePlugin will operate on any file in the dependency graph. I think that’s the same for this loader, I don’t think it will actually pick files directly from the file system

from string-replace-loader.

pietia avatar pietia commented on June 12, 2024

@fregante i would have to double check it but i didn't have luck to make DefinePlugin (search / replace functionality ) work with any other file than entry point.

from string-replace-loader.

fregante avatar fregante commented on June 12, 2024

In Refined GitHub we replace a variable in sub-dependencies of the entry point:

https://github.com/sindresorhus/refined-github/blob/f8c2fab4cfd8f85f19552a897f1a6df49ea441d9/webpack.config.ts#L108-L110

from string-replace-loader.

pietia avatar pietia commented on June 12, 2024

Thanks. Unfortunately, our project architecture is much more complicated and the file we would like to update with DefinePlugin is not referenced from entry point .

from string-replace-loader.

fregante avatar fregante commented on June 12, 2024

our project architecture is much more complicated

Right. As I said in my first paragraph:

webpack.DefinePlugin offer a native way to run simple replacements

What you want to do probably isn't covered by that plugin — which, by the way, works on any JS file; its import position doesn't matter as long as you use it as it's supposed to be used.

from string-replace-loader.

Va1 avatar Va1 commented on June 12, 2024

hi folks. the mentioned webpack.DefinePlugin is, first of all, a plugin, while this codebase is a loader. their use-cases seem to overlap, but are not equal. i am not sure of why it should be referenced here in this readme, if it is extensively documented in webpack docs and is, apparently, a standard way of performing replacements and some other things. why?

from string-replace-loader.

fregante avatar fregante commented on June 12, 2024

Because why use a 3rd party loader when you can do it "natively" and with less config?

string-replace-loader is useful for full string replacements, but 2 examples in the readme are a plain variable replacement that Webpack supports.

If the intent of this module is to help the user, let's direct them to better solutions.

from string-replace-loader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.