Comments (8)
Problem with a syntax like /foo/
is that it excludes paths. The other problem that I see is the level of verbosity and difficulty of reading, e.g., having slashes would require a backslash, but since that already has a meaning in a string two backslashes would be needed.
Anyway since the LHS would be primarily file based I wanted to opt-in for glob patterns, which just work as strings and are pretty well established. The only problem is that the RHS needs additional variables to cover the complexity of transformation (e.g., react
to React
).
In general the replacement for wildcards would be a problem that is hard to solve in my opinion (the $u
for making an uppercase version of the standard $1
was one trial, but there are countless other cases...). One other option here on the RHS is that a relative file path to a Node.js module could be taken, which exports a function returning that string.
Another radical solution that takes both - a simpler RHS and allowing a regular expression on the LHS is that externals are defined in a Node.js module already. If externals
is a string it would be evaluated as a (relative) path to a Node.js module; which exports a function that gets the requested module name (plus its path etc.) and either returns undefined (-> no external) or a string (replacement).
from parcel-plugin-externals.
Hm great question (and potential addition). Right now the externals are only determined by the peerDependencies
and the externals
(if used).
Maybe we could do the following regarding the externals
: For each key we check if wildcards (*) are used. Additionally, we can check if slashes (/) are used - leading to paths.
Examples:
react-*
would lead to all packages starting withreact-
./node_modules/react-*
would lead to all packages located innode_modules
that start withreact
./node_modules/*
would lead to all packages located innode_modules
The replacement rule then could be complicated... Suggestions are defined replacement variables such as $1
(replaced string), $u
(replaced string uppercase) etc.
Would be happy to hear how you solve it at the moment and what kind of syntax / options you could image for this feature!
from parcel-plugin-externals.
I think the examples you had there for $1
and $u
sound like a good way to go.
Edit: On second thought, you may want them to be in the form of ${number}{modifiers}
if you plan to have modifiers. $1
should be valid but if you wanted to modify it in some way you would provide $1u
, as an example.
from parcel-plugin-externals.
RegExp could maybe help, since e.g. "foobar".replace(/(foo)(bar)/, '$2$1'); // barfoo
from parcel-plugin-externals.
How is that connected to the problem @stoically (maybe I'm missing something)?
Note that the configuration is done in a JSON. Once a wildcard is detected a regex would be used underneath, hence the syntax for defining the replacement on the RHS.
from parcel-plugin-externals.
Since you were talking about wildcards, it wasn't clear to me that you had RegExp already in mind, sorry about that.
I was just thinking that it might be easy to implement to have a special syntax to designate the LHS as RegExp, and use the RHS as appropriate replacement string in that case. Maybe if the LHS matches /^\/(.*)\/([gimsuy]+)?$/
it could be treated as RegExp, e.g. "/my(regexp)/": "your$1"
from parcel-plugin-externals.
Landed in develop
and was published as a preview.
Current implementation:
Besides the "standard" ways of declaring externals you can also give it a string, e.g.,
{
"externals": "./tools/ruleFactory.js"
}
The rule factory module is just a simple Node.js module that exports a function:
const rx = /node_modules\/react-(.*?)\//;
module.exports = function(path) {
const result = rx.exec(path);
if (result) {
const suffix = result[1];
const name = suffix[0].toUpperCase() + suffix.substr(1);
return `react-${suffix} => React${name}`;
}
return undefined;
};
Essentially, you just return what would usually be in your hands. Since you get full paths you have flexibility, however, that comes with "responsibility".
Let me know what you think!
from parcel-plugin-externals.
Will be published in v3.
from parcel-plugin-externals.
Related Issues (17)
- External syntax HOT 4
- Ignores hoisted modules HOT 1
- How to alias React and ReactDOM as `wp.element`? HOT 12
- Broken output with "--bundle-node-modules" option HOT 7
- (Node 8.16.x) SyntaxError: Unexpected token { ... HOT 1
- Help how to 'externalize' all of WordPress' globals HOT 7
- How use parcel-plugin-externals properly in development/production mode ? HOT 4
- HTML Externals HOT 3
- Use @parcel/logger instead of console HOT 1
- Uncaught ReferenceError: React is not defined HOT 3
- Bundling fails when [email protected] is added to external HOT 1
- Can't tell if plugin is running HOT 2
- Parcel v2 HOT 3
- Exception on browser property set to false HOT 5
- How to make dependencies with slash "/" as external? HOT 4
- Support for fake modules? HOT 4
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 parcel-plugin-externals.