How to use babel-plugin-preval - 2 common examples

To help you get started, we’ve selected a few babel-plugin-preval examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nscozzaro / physics-is-beautiful / courses / static / courses / js / containers / StudioViews / EditorsViews / containers / LessonWorkSpace / Codesandbox / common / version.js View on Github external
// This is .js for preval

const versionType = preval`module.exports = (() => {
  if (process.env.NODE_ENV === 'development') {
    return 'DEV';
  }
  if (process.env.STAGING_BRANCH) {
    return 'PR';
  }
  return 'PROD';
})()`

const versionNumber = Math.floor(preval`module.exports = Date.now();` / 1000)

const shortCommitSha = preval(`
var execSync = require('child_process').execSync;
try {
  module.exports = execSync('git rev-parse --short HEAD').toString().trim();
} catch (e) {
  module.exports = 'unknown';
}
`)

export const getTimestamp = version => +version.split('-')[1]

export default preval(
  `module.exports = "${versionType}-${versionNumber}-${shortCommitSha}";`
)
github codesandbox / codesandbox-client / packages / common / src / version.js View on Github external
// This is .js for preval

const versionType = preval`module.exports = (() => {
  if (process.env.NODE_ENV === 'development') {
    return 'DEV';
  }
  if (process.env.STAGING_BRANCH) {
    return 'PR';
  }
  return 'PROD';
})()`;

const versionNumber = Math.floor(preval`module.exports = Date.now();` / 1000);

const shortCommitSha = preval(`
var execSync = require('child_process').execSync;
try {
  module.exports = execSync('git rev-parse --short HEAD').toString().trim();
} catch (e) {
  module.exports = 'unknown';
}
`);

export const getTimestamp = version => +version.split('-')[1];

export default preval(
  `module.exports = "${versionType}-${versionNumber}-${shortCommitSha}";`
);

babel-plugin-preval

Pre-evaluate code at build-time

MIT
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis

Popular babel-plugin-preval functions