BVB Source Codes

reactide Show index.js Source code

Return Download reactide: download index.js Source code - Download reactide Source code - Type:.js
  1. 'use strict';
  2.  
  3. var assign = require('object-assign');
  4. var babel = require('babel-core');
  5. var loaderUtils = require('loader-utils');
  6. var cache = require('./lib/fs-cache.js');
  7. var exists = require('./lib/helpers/exists')();
  8. var read = require('./lib/helpers/read')();
  9. var resolveRc = require('./lib/resolve-rc.js');
  10. var pkg = require('./package.json');
  11. var path = require('path');
  12.  
  13. var transpile = function(source, options) {
  14.   var result = babel.transform(source, options);
  15.   var code = result.code;
  16.   var map = result.map;
  17.  
  18.   if (map && (!map.sourcesContent || !map.sourcesContent.length)) {
  19.     map.sourcesContent = [source];
  20.   }
  21.  
  22.   return {
  23.     code: code,
  24.     map: map,
  25.   };
  26. };
  27.  
  28. module.exports = function(source, inputSourceMap) {
  29.   var result = {};
  30.  
  31.   // Handle filenames (#106)
  32.   var webpackRemainingChain = loaderUtils.getRemainingRequest(this).split('!');
  33.   var filename = webpackRemainingChain[webpackRemainingChain.length - 1];
  34.  
  35.   // Handle options
  36.   var globalOptions = this.options.babel || {};
  37.   var loaderOptions = loaderUtils.parseQuery(this.query);
  38.   var userOptions = assign({}, globalOptions, loaderOptions);
  39.   var defaultOptions = {
  40.     inputSourceMap: inputSourceMap,
  41.     sourceRoot: process.cwd(),
  42.     filename: filename,
  43.     cacheIdentifier: JSON.stringify({
  44.       'babel-loader': pkg.version,
  45.       'babel-core': babel.version,
  46.       babelrc: exists(userOptions.babelrc) ?
  47.           read(userOptions.babelrc) :
  48.           resolveRc(process.cwd()),
  49.       env: process.env.BABEL_ENV || process.env.NODE_ENV,
  50.     }),
  51.   };
  52.  
  53.   var options = assign({}, defaultOptions, userOptions);
  54.  
  55.   if (userOptions.sourceMap === undefined) {
  56.     options.sourceMap = this.sourceMap;
  57.   }
  58.  
  59.   if (options.sourceFileName === undefined) {
  60.     options.sourceFileName = path.relative(
  61.         options.sourceRoot,
  62.         options.filename
  63.     );
  64.   }
  65.  
  66.   var cacheDirectory = options.cacheDirectory;
  67.   var cacheIdentifier = options.cacheIdentifier;
  68.  
  69.   delete options.cacheDirectory;
  70.   delete options.cacheIdentifier;
  71.  
  72.   this.cacheable();
  73.  
  74.   if (cacheDirectory) {
  75.     var callback = this.async();
  76.     return cache({
  77.       directory: cacheDirectory,
  78.       identifier: cacheIdentifier,
  79.       source: source,
  80.       options: options,
  81.       transform: transpile,
  82.     }, function(err, result) {
  83.       if (err) { return callback(err); }
  84.       return callback(null, result.code, result.map);
  85.     });
  86.   }
  87.  
  88.   result = transpile(source, options);
  89.   this.callback(null, result.code, result.map);
  90. };
  91.  
downloadindex.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top