This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NODE_ENV='production' node src/index.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NODE_ENV='development' node src/index.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const block = sourceToAST('{}').body[0]; | |
/** | |
* If the value was true then set the blocks body to the consequent | |
* If the value was false and there is an alternate set the blocks body to the alternate | |
* If there is not alternate remove the entire node | |
*/ | |
if (result) { | |
block.body = node.consequent.body; | |
return block; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from this | |
if (process.env.NODE_ENV === 'production') { | |
module.exports = require('./cjs/react.production.min.js'); | |
} else { | |
module.exports = require('./cjs/react.development.js'); | |
} | |
// to this | |
{ | |
module.exports = require('./cjs/react.development.js'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { value } = literal; | |
const result = new Function(`return "${value}" ${operator} "${process.env.NODE_ENV}"`)(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (node.type === 'IfStatement') { | |
// This allows us to generate different bundles based on the NODE_ENV value, allowing development and production builds | |
// needs to be a binary expression | |
if (node.test.type !== 'BinaryExpression') return; | |
// check if either left or right are member expressions that look for the node env | |
// check if either the left or right string literal, if it is lets build and compare the two | |
const { left, right, operator } = node.test; | |
if ((left.type === 'MemberExpression' || right.type === 'MemberExpression') && (left.type === 'Literal' || right.type === 'Literal')) { | |
// the member expression and literal can be on either side of the test so figure that out and assign to variables |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"expression": { | |
"type": "MemberExpression", | |
"start": 0, | |
"end": 20, | |
"object": { | |
"type": "MemberExpression", | |
"start": 0, | |
"end": 11, | |
"object": { | |
"type": "Identifier", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function iifeTemplate(source) { | |
return `(function() {const process = {env: { NODE_ENV: 'development' }};${source}}())`; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (process.env.NODE_ENV === 'production') { | |
module.exports = require('./cjs/react.production.min.js'); | |
} else { | |
module.exports = require('./cjs/react.development.js'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Uncaught ReferenceError: process is not defined | |
at require_3c705474d87ac8a9b47623a9c3833989 (generated.js:1528) | |
at require_785ce0fa348dcb9b9692a0ce512f61fe (generated.js:20858) | |
at generated.js:22699 | |
at generated.js:22713 |
NewerOlder