小编Leo*_*Gao的帖子

从带有babel的node_modules导入模块但失败了

我用es6写了一个模块并发布到npm,我想在另一个项目中使用它,所以我输入如下:

import {ActionButton} from 'rcomponents'
Run Code Online (Sandbox Code Playgroud)

但它不起作用:

D:\github\blog\node_modules\rcomponents\src\actionButton.jsx:1
(function (exports, require, module, __filename, __dirname) { import React fro
                                                              ^^^^^^
SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Module._extensions..js (module.js:478:10)
    at Object.require.extensions.(anonymous function) [as .jsx] (D:\github\blog\
node_modules\babel\node_modules\babel-core\lib\api\register\node.js:214:7)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at D:\github\blog\node_modules\rcomponents\src\index.js:3:19
    at Object.<anonymous> (D:\github\blog\node_modules\rcomponents\src\index.js:
7:3)
Run Code Online (Sandbox Code Playgroud)

这是我在webpack中的js loader配置:

{ test: /\.jsx?$/, loader: `babel?cacheDirectory=${babelCache}` }
Run Code Online (Sandbox Code Playgroud)

当我尝试导入一个不是来自的模块时node_modules,babel工作得很好.但是导入一个模块node_modules,babel似乎不起作用?

reactjs babeljs

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

如何为Hexo添加路线?

在主题中,_config.yml有两个默认路由://archieves.有可能添加一条路线/about吗?

我尝试添加/about_config.yml,但Cannot GET /about/显示.

hexo

10
推荐指数
2
解决办法
4067
查看次数

使用节点子进程以编程方式执行exec'npm init',但不知道何时完成

我使用child_process.execrun npm init,我可以让它创建package.json,但是创建后,我的stdin似乎仍然打开,我想知道子进程何时完成,所以我也许关闭了stdin,但是我不知道它何时完成。

这是我的代码:

var child = exec('npm init', function (err, stdout, stderr) {

    console.log('over');
});
child.stdout.on('data', function(data) {

    process.stdout.write(data);

    //process.stdin.resume();
});
child.stdout.on('end', function() {
    console.log('end out');
});
child.stdout.on('close', function() {
    console.log('close out');
});
child.on('exit', function() {
    console.log('exit');
});
child.on('close', function() {
    console.log('close');
});
child.on('disconnect', function() {
    console.log('disconnect');
});

// read stdin and send to child process
process.stdin.on('readable', function() {

    var chunk = process.stdin.read();

    if(chunk !== null) {
        child.stdin.write(chunk);
    }
});
Run Code Online (Sandbox Code Playgroud)

完成创建package.json后,没有任何事件触发,那么如何在完成后将其关闭?

child-process node.js

7
推荐指数
1
解决办法
1240
查看次数

标签 统计

babeljs ×1

child-process ×1

hexo ×1

node.js ×1

reactjs ×1