我正在运行一个babel cli命令
babel src --out-dir lib
Run Code Online (Sandbox Code Playgroud)
将es6脚本从src复制到lib.但是,它不会复制我在src /文件夹中的css/scss文件.有没有办法让它复制它们?
我在使用mocha和babel编译器运行istanbul时遇到了一些问题.
我的所有测试都运行得很好,但在完成所有测试后,它会向我显示以下消息:
No coverage information was collected, exit without writing coverage information
而且它没有制作任何报道报道..
我正在运行的命令是:
NODE_ENV=test istanbul cover _mocha -- --require babel-core/register --recursive
该项目托管在github:https: //github.com/weslleyaraujo/react-flux-puzzle/tree/feat/unit-tests-24
任何想法可能是什么?
例如,我可以这样做:
import React from 'react';
import PanelA from './panelA.jsx';
import PanelB from './panelB.jsx';
React.render(
<PanelA />
<PanelB />,
document.body
);
Run Code Online (Sandbox Code Playgroud)
React将呈现的位置:
body
PanelA
PanelB
Run Code Online (Sandbox Code Playgroud)
目前我收到错误:
Adjacent JSX elements must be wrapped in an enclosing tag
Run Code Online (Sandbox Code Playgroud)
同时使用browserify和babelify进行转换
一切似乎都很好:http://d.pr/i/1aZxR 以下配置.
但是,当我运行代码时,我得到以下错误(通过webpack-dev-server):
Uncaught TypeError: __webpack_require__(...) is not a function(anonymous function) @ login.js:4__webpack_require__ @ bootstrap 38790ff45722f55eb700?6a08:50(anonymous function) @ bootstrap.js:2363__webpack_require__ @ bootstrap 38790ff45722f55eb700?6a08:50(anonymous function) @ app.38790ff45722f55eb700.js:29__webpack_require__ @ bootstrap 38790ff45722f55eb700?6a08:50webpackJsonpCallback @ bootstrap 38790ff45722f55eb700?6a08:21(anonymous function) @ app.38790ff45722f55eb700.js:1
angular.js:68 Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:nomod] Module 'app' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. …Run Code Online (Sandbox Code Playgroud) 先前:
var debug = require('debug')('http')
, http = require('http')
, name = 'My App';
Run Code Online (Sandbox Code Playgroud)
使用es6,如何像第一行一样立即导入和调用?
import debug from 'debug'();
Run Code Online (Sandbox Code Playgroud)
是不是不?
我有VSCode 0.5.0.我将compilerOptions标志设置为"ES6",编辑器开始识别我的ES6代码是正确的.我安装了babel.我的Mocha测试使用babel编译器,我的测试通过.当我使用babel-node启动它时,我的应用程序从命令行运行没有问题.当我从VSCode中调试应用程序时,它启动时没有ES6支持,并且应用程序因ES6语法问题而失败.是否有我错过的调试设置?
我在EC2上使用node.js.
我打字
EXPORT PORT=80
Run Code Online (Sandbox Code Playgroud)
在终端,我看到它在我输入EXPORT时正确保存它
但是当我使用以下命令运行我的node.js应用程序时:
...
console.log(process.env);
...
Run Code Online (Sandbox Code Playgroud)
当我使用sudo运行它时,PORT未在对象中列出:
sudo node app.js
Run Code Online (Sandbox Code Playgroud)
如何设置PORT,以便在使用sudo运行节点时可以从process.env对象访问它?
我无法获得异步/等待转换工作.我错过了什么?
我的.babelrc:
{
"presets": [ "es2015", "stage-0" ]
}
Run Code Online (Sandbox Code Playgroud)
我的package.json(剪掉):
{
"babel-core": "^6.1.2",
"babel-plugin-transform-runtime": "^6.1.2",
"babel-preset-es2015": "^6.1.2",
"babel-preset-stage-0": "^6.1.2"
}
Run Code Online (Sandbox Code Playgroud)
输出:
babel src/server
SyntaxError: src/server/index.js: Unexpected token (7:21)
5 |
6 | try {
> 7 | let server = await server('localhost', env.NODE_PORT || 3000)
| ^
8 | console.log(`Server started on ${server.info.uri}`)
9 | } catch (err) {
10 | console.error('Error starting server: ', err)
Run Code Online (Sandbox Code Playgroud) 我使用了安装Babel CLI(版本6)npm install --global babel-cli.然后我使用安装反应预设npm install --global babel-preset-react.
然后我.babelrc将项目目录中的文件设置为
{
"presets": ["react"]
}
Run Code Online (Sandbox Code Playgroud)
当我尝试构建一个JSX文件时,它失败了
Error: Couldn't find preset "react"
at OptionManager.mergePresets (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:310:17)
at OptionManager.mergeOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:270:12)
at OptionManager.addConfig (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:206:10)
at OptionManager.findConfigs (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:347:16)
at OptionManager.init (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:392:12)
at File.initOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:191:75)
at new File (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:122:22)
at Pipeline.transform (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/pipeline.js:42:16)
at transform (/usr/local/lib/node_modules/babel-cli/lib/babel/util.js:53:22)
at Object.compile (/usr/local/lib/node_modules/babel-cli/lib/babel/util.js:62:12)
Run Code Online (Sandbox Code Playgroud)
如果我安装没有--global标志的预设(即在本地安装在node_modules /文件夹中),那么构建工作.我如何设置让babel使用全局预设?
我知道至少有两种方法可以从.js文件中提取gettext字符串 - 使用python模式下的gettext解析器(我听说有一些缺点)和用python编写的Babel.
有没有办法从HTML文件中提取gettext字符串 - 或者更确切地说 - Javascript模板(下划线,小胡子等......).据我所知,也不是Babel或gettext.
我的一个朋友试图让Babel去做,但是它有一些严重的问题,错过了一些翻译等...
更新:朋友指导我一点,所以现在看来我可以按照我想要的方式提取所有字符串.我唯一缺少的是"翻译评论".我使用的命令是这样的:
find . -iname '*.html' -o -iname '*.js' | xargs xgettext --language=Python --from-code=utf-8 --keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3
Run Code Online (Sandbox Code Playgroud)
这将在关键字中包含pgettext和npgettext
更新2:我发现要提取HTML标记属性中的gettext消息,我必须在JS部分之间插入换行符.例如,我必须将此转换为:
<a href="" title="<%= ST.i18n.gettext('Click to add another row') %>"></a>
Run Code Online (Sandbox Code Playgroud)
进入:
<a href="" title="
<%= ST.i18n.gettext('Click to add another row') %>"></a>
Run Code Online (Sandbox Code Playgroud)
Python模式下的xgettext如果位于同一行,则不会提取gettext消息.这是一个似乎对我有用的快速黑客攻击.
更新3:似乎PHP模式下的xgettext从HTML中提取消息没有任何问题(至少使用Undsrscore模板),这也适用于翻译者评论.
find ../app -iname '*.html' | xargs xgettext --language=PHP --from-code=utf-8 -c --keyword=gettext --keyword=ngettext:1,2 --keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 -o translations.po
Run Code Online (Sandbox Code Playgroud)
这样,我可以在模板文件中保持正常的格式:
<a href="" title="<%= ST.i18n.gettext('Click to add another row') %>"></a>
Run Code Online (Sandbox Code Playgroud) babeljs ×8
node.js ×4
javascript ×3
ecmascript-6 ×2
babel ×1
browserify ×1
debugging ×1
gettext ×1
html ×1
istanbul ×1
mocha.js ×1
python ×1
reactjs ×1
sudo ×1
webpack ×1