-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
21 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
const { transformSync } = require('@babel/core'); | ||
|
||
/** | ||
* Babel-ifies the enclosed code, using the config below. | ||
* Babel-ifies the enclosed code, using the config below. Note that if the | ||
* IS_DEVELOPMENT_PREVIEW environment variable is set to 'true', the enclosed | ||
* code is returned verbatim. This is an optimization for the build preview. | ||
* | ||
* @param {import('handlebars').HelperOptions} options | ||
* @returns {string|null} | ||
*/ | ||
module.exports = function babel(options) { | ||
const srcCode = options.fn(this); | ||
return transformSync(srcCode, { | ||
compact: true, | ||
minified: true, | ||
comments: false, | ||
sourceType: 'script', | ||
presets: ['@babel/preset-env'], | ||
plugins: [ | ||
'@babel/syntax-dynamic-import', | ||
'@babel/plugin-transform-arrow-functions', | ||
'@babel/plugin-proposal-object-rest-spread', | ||
'@babel/plugin-transform-object-assign', | ||
] | ||
}).code; | ||
|
||
if (process.env.IS_DEVELOPMENT_PREVIEW === 'true' ) { | ||
return srcCode; | ||
} else { | ||
return transformSync(srcCode, { | ||
compact: true, | ||
minified: true, | ||
comments: false, | ||
sourceType: 'script', | ||
presets: ['@babel/preset-env'], | ||
plugins: [ | ||
'@babel/syntax-dynamic-import', | ||
'@babel/plugin-transform-arrow-functions', | ||
'@babel/plugin-proposal-object-rest-spread', | ||
'@babel/plugin-transform-object-assign', | ||
] | ||
}).code; | ||
} | ||
}; |