X Tutup
The Wayback Machine - https://web.archive.org/web/20201209133614/https://github.com/developit/microbundle/pull/692
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

Document @ for the --define option #692

Open
wants to merge 1 commit into
base: master
from

Conversation

@gregorym
Copy link

@gregorym gregorym commented Aug 8, 2020

I had to dig through the code in order to figure out how to replace an expression.
I was initially trying to do microbundle --define global=window which should actually be microbundle --define @global=window

I had to dig through the code in order to figure out how to replace an expression.
I was initially trying to do `microbundle --define global=window` which should actually be `microbundle --define @global=window`
@changeset-bot
Copy link

@changeset-bot changeset-bot bot commented Aug 8, 2020

💥 No Changeset

Latest commit: 71ea85b

Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂

If these changes should be published to npm, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@wardpeet
Copy link
Collaborator

@wardpeet wardpeet commented Aug 8, 2020

@gregorym Thank you for opening this PR. Could we instead add a small section to https://github.com/developit/microbundle#-usage--configuration- that explains how to do definitions with examples?

export function toReplacementExpression(value, name) {
// --define A="1",B='true' produces string:
const matches = value.match(/^(['"])(.+)\1$/);
if (matches) {
return [JSON.stringify(matches[2]), name];
}
// --define @assign=Object.assign replaces expressions with expressions:
if (name[0] === '@') {
return [value, name.substring(1)];
}
// --define A=1,B=true produces int/boolean literal:
if (/^(true|false|\d+)$/i.test(value)) {
return [value, name];
}
// default: string literal
return [JSON.stringify(value), name];
}

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

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.
X Tutup