我已经开始使用webpack2(准确地说v2.3.2),在重新创建配置后,我一直遇到一个我似乎无法解决的问题.我得到了(提前抱歉丑陋的转储):
ERROR in ./src/main.js
Module not found: Error: Can't resolve 'components/DoISuportIt' in '[absolute path to my repo]/src'
resolve 'components/DoISuportIt' in '[absolute path to my repo]/src'
Parsed request is a module
using description file: [absolute path to my repo]/package.json (relative path: ./src)
Field 'browser' doesn't contain a valid alias configuration
aliased with mapping 'components': '[absolute path to my repo]/src/components' to '[absolute path to my repo]/src/components/DoISuportIt'
using description file: [absolute path to my repo]/package.json (relative path: ./src)
Field 'browser' doesn't …Run Code Online (Sandbox Code Playgroud) 我有以下内容:
<Route name="app" path="/" handler={App}>
<Route name="dashboards" path="dashboards" handler={Dashboard}>
<Route name="exploreDashboard" path="exploreDashboard" handler={ExploreDashboard} />
<Route name="searchDashboard" path="searchDashboard" handler={SearchDashboard} />
<DefaultRoute handler={DashboardExplain} />
</Route>
<DefaultRoute handler={SearchDashboard} />
</Route>
Run Code Online (Sandbox Code Playgroud)
使用DefaultRoute时,SearchDashboard呈现不正确,因为任何*Dashboard都需要在Dashboard中呈现.
我希望"app"路由中的DefaultRoute指向Route"searchDashboard".这是我可以使用React Router做的事情,还是应该使用普通的Javascript(用于页面重定向)?
基本上,如果用户转到主页,我想将它们发送到搜索仪表板.所以我想我正在寻找相当于的React Router功能window.location.replace("mygreathostname.com/#/dashboards/searchDashboard");
React有很多方法可以使用PropTypes来检查prop的值.我经常使用的是React.PropTypes.shape({...}).但是,我最近遇到一种情况,我有一个内部有动态键/值的对象.我知道每个键应该是一个字符串(以已知格式),每个值应该是一个int.即使使用自定义道具验证功能,它仍然假设您知道道具的关键.如何使用PropTypes检查对象/形状的键和值是否正确?
...
someArray: React.PropTypes.arrayOf(React.PropTypes.shape({
// How to specify a dynamic string key? Keys are a date/datetime string
<dynamicStringKey>: React.PropTypes.number
}))
...
Run Code Online (Sandbox Code Playgroud)
所以:我想至少检查每个键的值是否为数字.理想情况下,我还希望能够检查密钥本身是否是正确格式的字符串.
是否可以ENV根据构建的值有条件地在Dockerfile中设置变量ARG?
例如:像
ARG BUILDVAR=sad
ENV SOMEVAR=if $BUILDVAR -eq "SO"; then echo "hello"; else echo "world"; fi
Run Code Online (Sandbox Code Playgroud)
更新:基于Mario答案的当前使用情况:
ARG BUILD_ENV=prod
ENV NODE_ENV=production
RUN if [ "${BUILD_ENV}" = "test" ]; then export NODE_ENV=development; fi
Run Code Online (Sandbox Code Playgroud)
然而,运行,--build-arg BUILD_ENV=test然后进入主机,我仍然得到
docker run -it mycontainer bin/bash
[root@brbqw1231 /]# echo $NODE_ENV
production
Run Code Online (Sandbox Code Playgroud) 我想知道是否有一种更好的方式来有条件地传递道具而不是使用if语句.
例如,我现在有:
var parent = React.createClass({
propTypes: {
editable: React.PropTypes.bool.isRequired,
editableOpts: React.PropTypes.shape({...})
},
render: function() {
if(this.props.editable) {
return (
<Child editable={this.props.editableOpts} />
);
} else {
// In this case, Child will use the editableOpts from its own getDefaultProps()
return (
<Child />
);
}
}
});
Run Code Online (Sandbox Code Playgroud)
有没有办法在没有if语句的情况下编写这个?我正在考虑JSX中的一种inline-if语句:
var parent = React.createClass({
propTypes: {
editable: React.PropTypes.bool.isRequired,
editableOpts: React.PropTypes.shape({...})
},
render: function() {
return (
<Child
{this.props.editable ? editable={this.props.editableOpts} : null}
/>
);
}
});
Run Code Online (Sandbox Code Playgroud)
总结:我正试图找到一种方法来定义一个道具Child,但是传递一个值(或做一些其他的),这样Child …
我有一个使用d3.js创建的强制布局
我想同时拥有可拖动力布局的正常功能以及缩放功能.
我基本上复制/粘贴了这个(http://jsfiddle.net/nrabinowitz/QMKm3/)代码的缩放代码.这与Mike Bostock在此(http://bl.ocks.org/mbostock/3680957)示例中使用的缩放方式相同.
这是我的代码:http://jsfiddle.net/kM4Hs/6/
从我的中可以清楚地看到,缩放工作正常,但我无法在力布局中选择单个节点并拖动它们.
我发现其他作者使用d3.v2.js而不是我正在使用的较新的d3.v3.js这个事实.当我将导入更改为v2时,它可以完美运行.但是,为了进步和一般良好的代码,我想尽可能使用v3.
<script type='text/javascript' src='http://d3js.org/d3.v3.min.js'></script>
Run Code Online (Sandbox Code Playgroud)
两个问题:为什么v3在v2没有时打破了力布局,更重要的是,我能做些什么,如果有的话,修复它?
提前致谢!
我使用Atom的linter,react和linter-jshint/ linter-jsxhint.在我的JSX文件中,我不断收到警告
警告:'import'仅在ES6中可用(使用esnext选项).(W119)
这非常简单.我做了一些搜索,发现这可以在jshintConfig选项中设置package.json(使用NPM时).我的项目使用NPM,我有一个package.json.我补充说:
"jshintConfig": {
"esnext": true
}
Run Code Online (Sandbox Code Playgroud)
之后,我做了重装,但警告仍然存在.我还修改了Atom()中的linter-jshint/ linter-jsxhintconfig config.cson:
"linter-jshint":
harmony: true
esnext: true
"linter-jsxhint":
harmony: true
esnext: true
Run Code Online (Sandbox Code Playgroud)
并做了重装,但也没有帮助.
那么:当使用linter-jshint/ linter-jsxhint作为Atom包时,如何设置esnext选项?
我将React版本从0.12.2升级到0.13.2,将我的React-Router从0.12.4升级到0.13.2.只进行这两个升级,没有别的,我现在加载我的网页/应用程序时出现以下错误:
Uncaught TypeError: Cannot read property '_currentElement' of null
Run Code Online (Sandbox Code Playgroud)
可能导致这种情况的任何想法?我似乎有一些潜在的React-Router错误的引用,但没有任何确定性.
导致错误的特定行是:
ReactRef.detachRefs(internalInstance, internalInstance._currentElement);
Run Code Online (Sandbox Code Playgroud)
更新1:我也刚刚从版本1.0.0升级到1.1.0并且根据@ BinaryMuse的评论将react-boot-bootstrap(我还没有实际使用)从0.9.1升级到0.13.0 - 没有变化.
更新2:经过进一步测试后,我将其缩小为react-d3的问题.从我的站点禁用react-d3代码会导致错误消失.我正在删除路由代码以使帖子更简洁,因为我现在相当确信react-router不会导致此问题.
更新3:感谢@CoryDanielson为react-d3创建新标签.
的package.json
{
"author": "me",
"name": "my project",
"description": "my awesome project",
"version": "0.1.0",
"dependencies": {
"bootstrap": "^3.3.2",
"d3": "^3.5.5",
"font-awesome": "^4.3.0",
"jquery": "^2.1.3",
"react": "^0.13.2",
"react-bootstrap": "^0.21.0",
"react-d3": "^0.3.1",
"react-router": "^0.13.2",
"react-router-bootstrap": "~0.13.0",
"reflux": "^0.2.6",
"uuid": "^2.0.1"
},
"devDependencies": {
"browser-sync": "^2.2.2",
"browserify": "^9.0.3",
"del": "^1.1.1",
"envify": "^3.4.0",
"gulp": "^3.8.11",
"gulp-css-url-adjuster": "^0.2.3",
"gulp-jshint": "^1.9.2", …Run Code Online (Sandbox Code Playgroud) 我想在root(centos:6)Docker容器中给我的root用户a .bashrc.但是,当我运行我的容器时,我发现.bashrc它还没有来源.可以这样做吗?
我的构建命令:
...
RUN touch .bashrc
RUN echo "iptables -t nat -A OUTPUT -d hostA -p tcp --dport 3306 -j DNAT --to hostB" >> .bashrc
...
Run Code Online (Sandbox Code Playgroud)
我的运行命令:
docker run -it --cap-add=NET_ADMIN myImage /bin/bash
Run Code Online (Sandbox Code Playgroud) 如何获取 ESLint 正在检查的文件列表?
我能找到的唯一关于它的讨论是这个 eslint 问题,其中存储库的成员建议运行DEBUG=eslint:* eslint. 然而,其输出却大得令人难以置信。
javascript ×5
reactjs ×4
d3.js ×2
docker ×2
atom-editor ×1
commonjs ×1
dockerfile ×1
eslint ×1
force-layout ×1
inline ×1
jshint ×1
jsxhint ×1
npm ×1
package.json ×1
react-d3 ×1
react-router ×1
routes ×1
svg ×1
typeerror ×1
typescript ×1
webpack ×1
webpack-2 ×1