cube-babel
Advanced tools
Comparing version 0.0.5 to 0.0.6
25
index.js
'use strict'; | ||
const path = require('path'); | ||
const babelCore = require('babel-core'); | ||
@@ -12,2 +13,22 @@ const _ = require('lodash'); | ||
function importPlugin(nameString) { | ||
let plugin = null; | ||
if (/^\//.test(nameString)) { | ||
// absolute import | ||
const pluginPath = nameString.slice(1); | ||
plugin = require(__dirname, '../..', pluginPath); | ||
} else if (/^(\.\/|\.\.\/)/.test(nameString)) { | ||
// relative import | ||
plugin = require(__dirname, '../..', nameString); | ||
} else if (/^(babel-plugin-|@\w+\/babel-plugin-)/.test(nameString)) { | ||
// full-name or with scope | ||
plugin = require(nameString); | ||
} else { | ||
// shorthand | ||
plugin = require('babel-plugin-' + nameString) | ||
} | ||
// 部分插件导出 { default: [Function] } 形式 | ||
return plugin.default ? plugin.default : plugin; | ||
} | ||
class BabelProcessor { | ||
@@ -60,5 +81,5 @@ constructor(cube, config) { | ||
if (Array.isArray(v) && typeof v[0] === 'string') { | ||
v[0] = require('babel-plugin-transform-' + v[0]); | ||
v[0] = importPlugin(v[0]); | ||
} else if (typeof v === 'string') { | ||
a[i] = require('babel-plugin-transform-' + v); | ||
a[i] = importPlugin(v); | ||
} | ||
@@ -65,0 +86,0 @@ }); |
{ | ||
"name": "cube-babel", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "cube babel processor", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -16,16 +16,3 @@ cube-babel | ||
{ | ||
presets: [ | ||
'react', | ||
[ | ||
'env', | ||
{ | ||
"targets": { | ||
"browsers": [ | ||
"chrome >= 50", | ||
"safari >= 7" | ||
] | ||
} | ||
} | ||
] | ||
], | ||
presets: [['es2015']], | ||
plugins: [ | ||
@@ -41,3 +28,1 @@ ['${plugin-name}', {/** ${config} **/}] | ||
更多配置,请参考babel文档 http://babeljs.io/docs/plugins/#official-presets | ||
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
5096
91
1
27
6
1