小编log*_*yth的帖子

使用npm进行安装时,请使用自定义目录名而不是node_modules

我创建一个package.json,我跑npm install,它工作正常.它node_modules在我的根文件夹中创建一个目录(我可以使用--prefix选项更改).但是,我不喜欢那么多的下划线.我想更改NPM将模块下载到的目录的名称.我希望它被命名nmodsnode-modules或类似的东西.

Bower可以通过读取当前目录中文件directory内的属性来做类似的事情.bowerrc.有没有办法对NPM做同样的事情?

config node.js npm

45
推荐指数
2
解决办法
2万
查看次数

让babel排除测试文件

在我的构建步骤中,我使用babel将代码转换为es5(从srcdist).如何使其排除以.test.js?结尾的文件?

的package.json

"scripts": {
  "build": "babel src --out-dir dist",
Run Code Online (Sandbox Code Playgroud)

.babelrc

{
  "presets": [ "es2015" ],
  "ignore": "\\.test\\.js"
}
Run Code Online (Sandbox Code Playgroud)

node.js babeljs

43
推荐指数
2
解决办法
2万
查看次数

模块构建失败:ReferenceError:[BABEL]

我有这个配置

的package.json

{
  "name": "app02",
  "version": "1.0.0",
  "description": "",
  "main": "webpack.config.js",
  "dependencies": {
    "react": "^0.14.3"
  },
  "devDependencies": {
    "babel-core": "^6.2.1",
    "babel-loader": "^6.2.0",
    "babel-preset-es2015": "^6.1.18"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "private": true
}
Run Code Online (Sandbox Code Playgroud)

webpack.config.js

module.exports = {
  entry: "./src/main.js",
  output: {
    path: __dirname + "/public",
    filename: "bundle.js"
  },
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel',
        query: {
          presets: ['react', 'es2015']
        }
      }
    ]
  }
} …
Run Code Online (Sandbox Code Playgroud)

npm reactjs webpack babeljs

40
推荐指数
1
解决办法
3万
查看次数

需要Babel"7.0.0-0",但加载了"6.26.3"

当我按照其他类似的报告时,无论我尝试安装(babel明智),都会继续收到此错误.这是堆栈跟踪:

error: bundling failed: Error: Requires Babel "^7.0.0-0", but was
loaded with "6.26.3". If you are sure you have a compatible version of
@babel/core, it is likely that something in your build process is
loading the wrong version. Inspect the stack trace of this error to
look for the first entry that doesn't mention "@babel/core" or
"babel-core" to see what is calling Babel. (While processing preset:
"C:\\Users\\Admin-ESS\\Absent\\node_modules\\@babel\\preset-env\\lib\\index.js")
    at throwVersionError (C:\Users\Admin-ESS\Absent\node_modules\@babel\preset-env\node_modules\@babel\helper-plugin-utils\lib\index.js:65:11)
    at Object.assertVersion (C:\Users\Admin-ESS\Absent\node_modules\@babel\preset-env\node_modules\@babel\helper-plugin-utils\lib\index.js:13:11)
    at _default (C:\Users\Admin-ESS\Absent\node_modules\@babel\preset-env\lib\index.js:150:7)
    at C:\Users\Admin-ESS\Absent\node_modules\@babel\preset-env\node_modules\@babel\helper-plugin-utils\lib\index.js:19:12
    at C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\file\options\option-manager.js:317:46 …
Run Code Online (Sandbox Code Playgroud)

babel reactjs babeljs react-native

33
推荐指数
5
解决办法
2万
查看次数

Webpack没有将ES6转换为ES5

我对Webpack很新.我想我做错了.我想使用babel将ES6功能转换为ES5功能.所以我做了一些研究,发现了babel-loader.但是,我不确定我在做什么.

我运行了npm install babel-loader --save-dev,它被添加到我的package.json中

// package.json

{
  "name": "kanban",
  "version": "1.0.0",
  "description": "kanban",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.3.21",
    "babel-loader": "^6.2.0",
    "html-webpack-plugin": "^1.7.0",
    "json-loader": "^0.5.4",
    "webpack": "^1.12.9"
  }
}
Run Code Online (Sandbox Code Playgroud)

// webpack.config.js

var path = require('path');
var HtmlwebpackPlugin =  require('html-webpack-plugin');

const PATHS = {
  app: path.join(__dirname, 'app'),
  build: path.join(__dirname, 'build')
};

module.exports = {
  entry: PATHS.app,
  output: {
    path: PATHS.build,
    filename: 'bundle.js'
  },
  plugins: …
Run Code Online (Sandbox Code Playgroud)

node.js webpack babeljs

32
推荐指数
3
解决办法
3万
查看次数

Module.exports和es6导入

与巴贝尔发生反应.我对import和module.exports感到困惑.在将ES6代码转换为ES5时,我假设babel将导入和导出分别转换为require和module.exports.

如果我从一个模块导出一个函数并在另一个模块中导入该函数,代码执行正常.但是如果我使用module.exports导出函数并使用"import"导入,则会在运行时抛出错误,表示它不是函数.

我做了一个例子.

// Tiger.js
function Tiger() {
    function roar(terrian){
        console.log('Hey i am in ' +  terrian + ' and i am roaing');
    };
    return roar;
}

module.exports = Tiger;

// animal.js
import { Tiger } from './animals';

var animal = Tiger();
animal("jungle");
Run Code Online (Sandbox Code Playgroud)

我使用预设es2015的babel进行反编译.这给了我以下错误

未捕获的TypeError:(0,_ animals.Tiger)不是函数

但是如果我删除它module.exports = Tiger;并用它替换export { Tiger };它工作正常.

我在这里失踪了什么?

编辑: 我使用browserify作为模块捆绑器.

babeljs es6-module-loader

25
推荐指数
3
解决办法
2万
查看次数

BABEL注意:代码生成器已经优化了"app.js"的样式,因为它超过了Meteor中的"100KB"的最大值

我在meteor中的app.js文件超过了100KB的限制我该如何解决这个问题呢?它会影响我的申请吗?这是因为安装包吗?

meteor babeljs

23
推荐指数
2
解决办法
3万
查看次数

Babel中的Javascript代理支持

我正在使用babelify版本6.3.0设置为第0阶段.ES6/ES7工作得很好.但是当我尝试使用Javascript的代理功能时:

set product(product={}) {
  this._product = new Proxy({}, {})
}
Run Code Online (Sandbox Code Playgroud)

我明白了:

ReferenceError: Can't find variable: Proxy
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

javascript proxy babeljs

22
推荐指数
2
解决办法
1万
查看次数

找不到模块:错误:无法解析模块

我创建了一个使用babel和webpack的简单项目.我在这里查了一下

https://github.com/abhitechdojo/MovieLensReact.git

在我的根文件夹中,我有两个文件script1.js和script2.js.我的webpack.config.js看起来像

module.exports = {
    entry : {
        main: [
            'script1.js', 'script2.js'
        ]
    },
    output : {
        filename: 'public/main.js'
    },
    "module" : {
        "loaders" : [
            {
                "test": /\.jsx?/,
                "exclude": /node_modules/,
                loader: 'babel',
                query: {
                    presets: ['es2015', 'react']
                }               
            }
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我运行webpack时.它找不到任何javascript文件

ERROR in multi main
Module not found: Error: Cannot resolve module 'script1.js' in /Users/abhishek.srivastava/MyProjects/MovieLensReact
 @ multi main

ERROR in multi main
Module not found: Error: Cannot resolve module 'script2.js' in /Users/abhishek.srivastava/MyProjects/MovieLensReact
 @ multi main
Run Code Online (Sandbox Code Playgroud)

javascript webpack babeljs

21
推荐指数
1
解决办法
3万
查看次数

使用fs.readFile在Node.js中读取和返回多个文件

我正在编写一个简单的请求处理程序来返回一对css文件.使用fs.readFileSync这很容易.但是,我很难使用异步版本的readFile完成相同的任务.以下是我的代码.让我的response.write()方法调用分成两个不同的回调似乎是有问题的.有人能指出我做错了什么吗?有趣的是,如果我在第一个else语句中放入response.end(),这段代码就可以工作.但是,这会产生一个问题,即第二个css文件没有返回(因为response.end()已被触发).

function css(response) {

  response.writeHead(200, {"Content-Type": "text/css"});

  fs.readFile('css/bootstrap.css', function(error, content){
    if(error){
      console.log(error);
    }
    else{
      response.write(content);
    }
  });
  fs.readFile('css/bootstrap-responsive.css', function(error, content){
    if(error){
      console.log(error);
    }
    else{
      response.write(content)
    }
  });
  response.end();
}
Run Code Online (Sandbox Code Playgroud)

node.js

19
推荐指数
2
解决办法
3万
查看次数