Comments (10)
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.
I've refactored my project so that i can use DefinePlugin , so - case closed.
from string-replace-loader.
@fregante Isn't that DefinePlugin can operate only on entry points while string-replace-loader can update any file ?
from string-replace-loader.
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.
@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.
In Refined GitHub we replace a variable in sub-dependencies of the entry point:
- content.ts is the entry point
- the variable is in a file imported by content.ts: https://github.com/sindresorhus/refined-github/blob/f8c2fab4cfd8f85f19552a897f1a6df49ea441d9/source/features/copy-on-y.tsx#L21
from string-replace-loader.
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.
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.
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.
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)
- unable to replace assetspath in js, but success in html, using webpack4 HOT 4
- Getting an unexpected token error when trying to process .json files HOT 2
- it not works! I want to replace dev code in prod env! HOT 3
- Replace failed (strict mode) : $VERSION → hello HOT 1
- Strict mode: Error: Cannot replace x → y HOT 1
- 'replace' should allow both strings and functions HOT 1
- Add RegExp type search. HOT 5
- Replace strings of other bundles HOT 1
- Unexpected token on 'static' declaration HOT 1
- Webpack v5 support HOT 2
- Callback replace not working HOT 4
- support callback function in options, make sure user can custom personal search rule. HOT 2
- How can I get current filename from rule.test in replace function? HOT 2
- Webpack 4 - Replace values inside json file HOT 1
- Can use in antd-design prefixCls replace?
- How can I get a file name in the replace fn? HOT 1
- add check for changes before writing to file
- Как заменить подстроку в строке в файле HTML в Webpack 5 HOT 3
- Does not replace text while app running with hot-reload. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from string-replace-loader.