Git Product home page Git Product logo

blog's People

Contributors

haaaaadion avatar

Stargazers

 avatar

Watchers

 avatar  avatar

blog's Issues

命令

MAC 显示隐藏目录

Command + Shift + .

设置文件权限为777:

chmod -R  777 ./*

Mac切换JAVA_HOME版本

// 确保切到到这个目录
$cd ~

// JAVA_HOME 文件
$vim . bash_profile

// 切换JAVA_HOME版本保存后执行
$source .bash_profile

其他命令

// 查看所有JAVA_HOME版本
$/usr/libexec/java_home -V

根据地址获取图片Blob

function getImageBlob(url, cb) {
  const xhr = new XMLHttpRequest();
  xhr.open('get', url, true);
  xhr.responseType = 'blob';
  xhr.onload = () => {
    if (this.status === 200) {
      if (cb) cb(this.response);
    }
  };
  xhr.send();
}

function preView(url) {
  const reader = new FileReader();

  getImageBlob(url, (blob) => {
    reader.readAsDataURL(blob);
  });

  reader.onload = (e) => {
    console.log(e.target.result);
  };
}

// 调用
preView('http://www.you-img-url.com/url.jpg');

JavaScript 删除数组内元素

var arr=['a','b','c'];

若要删除其中的'b',有两种方法:

1. delete方法:delete arr[1]

这种方式数组长度不变,此时arr[1]变为undefined了,但是也有好处原来数组的索引也保持不变,此时要遍历数组元素可以才用

for(index in arr){
   document.write('arr['+index+']='+arr[index]);
}

这种遍历方式跳过其中undefined的元素

  * 该方式IE4.o以后都支持了

2.数组对象splice方法

arr.splice(1,1);

这种方式数组长度相应改变,但是原来的数组索引也相应改变
splice参数中第一个1,是删除的起始索引(从0算起),在此是数组第二个元素
第二个1,是删除元素的个数,在此只删除一个元素,即'b';
此时遍历数组元素可以用普通遍历数组的方式,比如for,因为删除的元素在
数组中并不保留
  * 该方法IE5.5以后才支持
值得一提的是splice方法在删除数组元素的同时,还可以新增入数组元素
比如arr.splice(1,1,'d','e'),d,e两个元素就被加入数组arr了
结果数组变成arr:'a','d','e','c'

JavaScript通过设置数组的length属性来截断数组是惟一一种缩短数组长度的方法.如果使用delete运算符来删除数组中元素,虽然那个元素变成未定义的,但是数组的length属性并不改变两种删除元素,数组长度也改变的方法.

 /*
  * 方法:Array.remove(dx)
  * 功能:删除数组元素.
  * 参数:dx删除元素的下标.
  * 返回:在原数组上修改数组
  */
//经常用的是通过遍历,重构数组.
Array.prototype.remove=function(dx)
 {
  if(isNaN(dx)||dx>this.length){return false;}
  for(var i=0,n=0;i<this.length;i++)
  {
    if(this[i]!=this[dx])
    {
      this[n++]=this[i]
    }
  }
  this.length-=1
 }
 a = ['1','2','3','4','5'];
 alert("elements: "+a+"nLength: "+a.length);
 a.remove(0); //删除下标为0的元素
 alert("elements: "+a+"nLength: "+a.length);
/*
  * 方法:Array.baoremove(dx)
  * 功能:删除数组元素.
  * 参数:dx删除元素的下标.
  * 返回:在原数组上修改数组.
  */
  
 //我们也可以用splice来实现.
  
 Array.prototype.baoremove = function(dx)
 {
  if(isNaN(dx)||dx>this.length){return false;}
  this.splice(dx,1);
 }
 b = ['1','2','3','4','5'];
 alert("elements: "+b+"nLength: "+b.length);
 b.baoremove(1); //删除下标为1的元素
 alert("elements: "+b+"nLength: "+b.length);

我们知道,在IE5或更低的版本中,JavaScript的Array(数组)对象并未提供现成的删除数组元素的方法。在IE5.5+的版本中,虽然有splice方法,但是并不是删除某一项(或几项),而仅仅是将某一项(或几项)的值清除,也就是说该项仍然存在,数组的长度并没有改变。

  事实上,我们可以自己为数组增加一个删除方法(注意,这里指的是将数组的某一项真正的从数组成员中移除)。或许你会想到用循环来为数组重新赋值,这样做当然可以,但效率很低。

  下面我们介绍利用Array对象的两个方法slice、concat来自定义删除数组的方法。

  具体代码如下,请注意里面的注释。

Array.prototype.del=function(n) { //n表示第几项,从0开始算起。
//prototype为对象原型,注意这里为对象增加自定义方法的方法。
 if(n<0) //如果n<0,则不进行任何操作。
  return this;
 else
  return this.slice(0,n).concat(this.slice(n+1,this.length));
  /*
   concat方法:返回一个新数组,这个新数组是由两个或更多数组组合而成的。
         这里就是返回this.slice(0,n)/this.slice(n+1,this.length)
         组成的新数组,这中间,刚好少了第n项。
   slice方法: 返回一个数组的一段,两个参数,分别指定开始和结束的位置。
  */
}
//我们来试一试这个自己增加的方法
var test=new Array(0,1,2,3,4,5);
test=test.del(3); //从0算起,这里也就是删除第4项。
alert(test);

转自: js 删除数组几种方法

React-native 问题汇总

官方详细问题汇总

Genymotion模拟器

运行react-nativec run-android安装到安卓模拟器Genymotion时出现错误:

Could not run adb reverse: Command failed: D:\Android\sdk/platform-tools/adb reverse tcp:8081 tcp:8081

执行adb命令adb reverse tcp:8081 tcp:8081出现错误:

adb server version (32) doesn't match this client (36); killing...
error: could not install *smartsocket* listener: cannot bind to 127.0.0.1:5037: 通常每个套接字地址(协议/网络地址/端口)只允许使用次。 (10048)      
could not read ok from ADB Server
* failed to start daemon *
error: cannot connect to daemon

解决办法:

设置GenymotionAndroid SDK位置

image

辅助解决办法:

tasklist /fi "PID eq 5037"           //查看占用了5037端口的进程
taskkill /pid 5037 /f                  //终止pid为5037的进程, /f表示为强制
taskkill /F /IM adb.exe             //直接强制终止adb
adb kill-server                          //关闭adb
adb start-server                       //开启adb

运行react-native run-android出错

运行react-native run-android出现错误:
image

解决办法:

降低gradle版本(参照下图)

image

ListView 修改数据重新渲染

使用cloneWithRows更新数据时, 如只更新该数据中的某一字段, 这条数据是不会被从新渲染, 需要整条记录替换更新才能被重新渲染, 数据结构如下:

var list = [
    {
    name: 'dion',
    age: '18'
    },
    {
        name: 'jack',
        age: '22'
    }
];

如果需要更新jackage20

//这样不会被 ListView 重新渲染
list[1].age = 20;
ds.cloneWithRows(list);
 //整条记录更新才会被 ListView 重新渲染
list[1] = {name: 'jack', age: '20'};
ds.cloneWithRows(list);

moment.js

format()参数

标识 输出
M 1 2 ... 11 12
Mo 1st 2nd ... 11th 12th
MM 01 02 ... 11 12
MMM Jan Feb ... Nov Dec
MMMM January February ... November December
Q 1 2 3 4
天数(月) D 1 2 ... 30 31
Do 1st 2nd ... 30th 31st
DD 01 02 ... 30 31
天数(年) DDD 1 2 ... 364 365
DDDo 1st 2nd ... 364th 365th
DDDD 001 002 ... 364 365
Day of Week d 0 1 ... 5 6
do 0th 1st ... 5th 6th
dd Su Mo ... Fr Sa
ddd Sun Mon ... Fri Sat
dddd Sunday Monday ... Friday Saturday
星期(本地) e 0 1 ... 5 6
星期(ISO) E 1 2 ... 6 7
周数 w 1 2 ... 52 53
wo 1st 2nd ... 52nd 53rd
ww 01 02 ... 52 53
周数(ISO) W 1 2 ... 52 53
Wo 1st 2nd ... 52nd 53rd
WW 01 02 ... 52 53
YY 70 71 ... 29 30
YYYY 1970 1971 ... 2029 2030
周、年 gg 70 71 ... 29 30
gggg 1970 1971 ... 2029 2030
周、年(ISO) GG 70 71 ... 29 30
GGGG 1970 1971 ... 2029 2030
AM/PM A AM PM
a am pm
H 0 1 ... 22 23(24小时)
HH 00 01 ... 22 23(24小时)
h 1 2 ... 11 12(12小时)
hh 01 02 ... 11 12(12小时)
m 0 1 ... 58 59
mm 00 01 ... 58 59
s 0 1 ... 58 59
ss 00 01 ... 58 59
分数秒 S 0 1 ... 8 9
SS 00 01 ... 98 99
SSS 000 001 ... 998 999
SSSS ... SSSSSSSSS 000[0..] 001[0..] ... 998[0..] 999[0..]
时区 z or zz EST CST ... MST PST 注意: 自 1.6.0版本后,z/zz格式标识不再支持 查看详细
Z -07:00 -06:00 ... +06:00 +07:00
ZZ -0700 -0600 ... +0600 +0700
UNIX时间戳(秒级) X 1360013296
NIX时间戳(毫秒级) x 1360013296123

本地化格式

因为不同地区的首选格式不同,这里还提供了一些特殊标识时用于moment的本地格式化。在这些格式中,格式标识大小写作用相同:

时间 LT 8:30 PM
时间和秒 LTS 8:30:25 PM
数字月、日、年 L 09/04/1986
  l 9/4/1986
月名、日、年 LL September 4 1986
  ll Sep 4 1986
月名、日、年、时间 LLL September 4 1986 8:30 PM
  lll Sep 4 1986 8:30 PM
月名、日、星期、年、时间/b> LLLL Thursday, September 4 1986 8:30 PM
  llll Thu, Sep 4 1986 8:30 PM

可能会出现时区不准确的情况,比如转换成国际时间后会+8小时,可以在转换前调用utc():

moment(time).utc().format()

ThreeJS to wx

ImageBitmap is not defined

Three.js源码中的|| image instanceof ImageBitmap删除

document. createElementNS is not a function

weapp-adapter.js document 的定义中添加 createElementNS方法

createElementNS: function createElementNS(nameSpace, tagName) {
      return this.createElement(tagName)
}

_eb7dc139-b906-42e8-beca-68d1310b1574

关于物理引擎的复合刚体模型,这里使用Connon.js

Cannon.js complex shapes

移动质量中心

compound body center of mass

移动旋转中心

Position a body in cannon.js relative to local rotation

React 问题汇总

基础文章

  1. React
  2. Redux
  3. ECMAScript 6入门
  4. React-router

css in js选型问题

css-modules

基于webpack,几乎等同传统css样式,也可以使用less sass,css样式在组件中使用后会在页面自动加载.
在做服务器端渲染的时候需要使用css-modules-require-hook,这个库能让node.js识别css文件且同步你的自定义hash类名(但也就只是获取类名让前后端渲染类名一致,具体的样式还是需要等待javascript进行加载插入
教程可以参考阮一峰老师的文章

csjs

css in js,库比较轻便,功能也比较简单,但每个class都会hash重命名,不能定于"静态全局类名",css样式可自定义获取加载

j2c

css in js,功能比较强大,拥有类似less sass的层叠样式编辑,继承,hash类名(hash后类名会带有j2c标识且较长),全局静态类名,css样式可以自定义获取加载.
但在做服务器端渲染的时候和组件引用同一份样式文件生成出来的类名却不同(hash值不同),暂时没有好的解决方法

使用原生JavaScript

示例代码:

let styles = `
    .title{
        color: #f00;
    }
`
console.log(styles);
//.title{
//    color: #f00;
//}

配合insert-css github可以把css代码插入到<head>

require('insert-css')(styles);

使用这种方法优势也很明显,不依赖第三方库,简单直接方便,开发过程中可以用css调试完后直接把css代码直接复制到let styles = ```封装,如果想实现hash值类名可以配合csjs`库来实现,原生样式用于全局样式定义,示例如下:

const csjs = require('csjs');

const styles = csjs`
    .title {
        color: #f00;
    }
`;

export default`
    ${csjs.getCss(styles)}
    .global{
        font-size: 12px
    }
`
//结果
//.title_KvcoI {
//    color: #f00;
//}
//.global{
//    font-size: 12px
//}

各种css in js库传送门

extract-text-webpack-plugin

extract-text-webpack-plugin
基于webpack打包css文件,可以搭配css-modules使用,使用后css-modules将不会自动插入css代码,需要手动加载
示例如下:

const ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
    //...
    module: {
        loaders: [
            {
                test: /\.css$/,
                loader: ExtractTextPlugin.extract('style-loader', 'css-loader?modules')
            }
        ]
    },
    //...
    plugins: [
        new ExtractTextPlugin("qqq/[name]-[chunkhash].css", {
            allChunks: true
        })
    ]
    //...
}

因为使用extract-text-webpack-plugin生成的文件可能需要带有'hash',所以在获取文件路径的时候无法静态获取,可以使用assets-webpack-plugin

assets-webpack-plugin

assets-webpack-plugin
基于webpack进行打包文件时,使用assets-webpack-plugin能获取记载的css js等文件
使用extract-text-webpack-plugin的示例进行扩展:

//打包的代码就不重复了,只需要加上`AssetsPlugin`实例就可以了
const AssetsPlugin = require('assets-webpack-plugin');

module.exports = {
    //...
    plugins: [
        new AssetsPlugin({filename: 'assets.json', path: './public/static/js-built'}),
        new ExtractTextPlugin(...)
    ]
    //...
}

webpack-isomorphic-tools

webpack-isomorphic-tools
引用别人的原话就是:

这个东西的作用就是帮你把 Webpack 为客户端处理的各种模块解析对应在服务端的实现都做好了,你按照它的说明写点代码整合到自己的架构中即可,比较快捷实用,不过也是蛮新的一个项目里面有坑几何我就没法儿说了。原文

React-router路径问题

单考虑前端的话可以使用hashHistory来做,路径样式如下
但如果要考虑同构就需要用browserHistory来代替,路径的样式如下
引用别人的原话

URL 中的 hash 部分不会发送到服务器,因此服务器端不能根据 hash 区分请求 URL,还好 react-router 支持 browserHistory + HTML5 history API 方式的路由。原文

使用browserHistory后因为用到HTML5所以会有兼容问题.
如果使用hashHistory想要去除?_k=9d95p3这个hash值可以使用外部的history库, 参考代码:

import createHistory from 'history/lib/createHashHistory'

//使用apphistory代替hashHistory
const apphistory = useRouterHistory(createHistory)({
    queryKey: false
})

其他同构文章可以参考:

  1. React服务器端渲染实践小结
  2. React同构直出优化总结
  3. (番外篇) 同构化的 React + Redux 服务端渲染
  4. React Router最新指南与异步加载实践

同构按需加载

require.ensure()

基于webpack + react-router使用require.ensure,参考代码如下:

const routes = {
    component: Init,
    childRoutes: [
        {
            path: '/',
            indexRoute: {
                getComponent: (nextState, cb) => {
                    require.ensure([], function (require) {
                        cb(null, require("../containers/essay"));
                    }, 'essay');
                }
            }
        },
        {
            path: 'posts',
            getComponent: (nextState, cb) => {
                require.ensure([], function (require) {
                    cb(null, require("../containers/posts"));
                }, 'posts');
            }
        }
    ]
};

require.ensure()会按照代码生成文件,以上代码require.ensure()会生成两份文件,分别是essay.js, posts.js最后的字符串(essay, posts)指的就是webpack.config.jschunkFilename中的[name].js
因为require.ensure()是基于webpack所以在node.js是找不到这个方法的,所以在同构的时候需要自行判断服务端与前端分别的加载方法.如果是服务端时则使用正常的require(),前端则使用require.ensure().
提供一下方法判断:

function getAsyncComponent(cb, path){
    if (typeof require.ensure != 'function'){
        cb(null, require(path));
        return false;
    }
    return true;
}

!!注意!! require.ensure()方法中的'require()'方法不能使用变量传递路径, 必须使用字符串否则会出错!

//这样是会出错的
getComponent: (nextState, cb) => {
    require.ensure([], function (require) {
        cb(null, require(path));
    }, 'essay')
}

//这样才可以
getComponent: (nextState, cb) => {
    require.ensure([], function (require) {
        cb(null, require("../containers/essay"));
    }, 'essay')
}

bundle-loader

除了上面的require.ensure()还有另一种类似的方法,就是bundle-loader,介绍可以去官方文档查看,具体用法:

function lazyLoadComponent(lazyModule) {  
  return (location, cb) => {
    lazyModule(module => cb(null, module))
  }
}

const routes = {
    component: Shell(Init),
    childRoutes: [
        {
            path: 'essay',
            getComponent: lazyLoadComponent(require('bundle?lazy&name=essay!../containers/essay'));
            }
        }
    ]
};

require前加上bundle?lazy表示这个组件需要进行异步加载,&name=essay表示生成chunk的名称
加载bundle?lazy之后的组件返回的并不是组件本身而是bundle函数,需要像上面再调用这个函数才能获取组件

另外可以不用每次调用require()都加上bundle?lazy,在webpack.config.js设置loader可以指定匹配文件都使用异步方法加载, 可以参考Implicit Code Splitting and Chunk Loading with React Router and Webpack

webpack热加载

  1. node.js + express可以使用webpack-dev-middleware
  2. node.js + koaV2可以使用koa-webpack-middleware(官方推荐方法),按照官方示例测试后,发现使用会页面无法正常显示,会自动进行下载,推测是header设置问题?具体暂时没有深入研究.
    转而使用koa-webpack-dev-middleware + koa-webpack-hot-middleware,使用方法与上面的基本一致,库语法使用koaV1,可以使用koa-convert封装使用
    参考文章:
  3. Express结合Webpack的全栈自动刷新
  4. koa中webpack热加载&&NODE_ENV配置

Babel解析问题

babel命令放到package.json里面出错
可以先更新babel相关库
非全局执行的babel命令需要添加.babelrc文件
具体配置:

{
	"presets": [
		"es2015",
		"react",
		"stage-2"
	],
	"plugins": []
}

默认解析出来的文件对export default {}支出不好导致不能正常require()加载,可以使用babel-plugin-add-module-exports来解决

使用koa + node.js搭建的服务器解析后出现以下错误:

        var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(ctx, next) {
                                     ^

ReferenceError: regeneratorRuntime is not defined
    at D:\luoo\nodejs\babel\routes\index-koa2.js:79:38
    at route (D:\luoo\nodejs\babel\routes\index-koa2.js:140:6)
    at Object.<anonymous> (D:\luoo\nodejs\babel\server.js:79:31)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Function.Module.runMain (module.js:575:10)
    at startup (node.js:160:18)
    at node.js:449:3

这里引用阮一峰老师原话:

Babel默认只转换新的JavaScript句法(syntax),而不转换新的API,比如Iterator、Generator、Set、Maps、Proxy、Reflect、Symbol、Promise等全局对象,以及一些定义在全局对象上的方法(比如Object.assign)都不会转码。
使用babel-polyfill库为环境提供一个垫片
在文件头加入下面代码:

import 'babel-polyfill';
// 或者
require('babel-polyfill');

最终配置:
.babelrc

{
	"presets": [
		"es2015",
		"react",
		"stage-2"
	],
	"plugins": [
		"add-module-exports"
	]
}

package.json

{
//...
  "devDependencies": {
    "babel-cli": "^6.14.0",
    "babel-core": "^6.18.2",
    "babel-eslint": "^6.1.0",
    "babel-loader": "^6.2.7",
    "babel-plugin-add-module-exports": "^0.2.1",
    "babel-polyfill": "^6.9.1",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-react": "^6.5.0",
    "babel-preset-stage-0": "^6.5.0",
    "babel-preset-stage-2": "^6.18.0",
    "babel-preset-stage-3": "^6.17.0",
  }
//...
}

参考文章:

  1. Babel 入门教程
  2. Babel 使用指南
  3. ES2015 & babel 实战:开发 NPM 模块

node.js 开启Gzip

node.js + express

执行命令下载包
npm install compression --save-dev

加载包

compression = require('compression');
app.use(compression());

整体代码

var express = require('express'),
    app = express(),
    path = require('path'),
    compression = require('compression');

app.use(compression());
app.set( 'view engine', 'html' );
app.engine( '.html', require( 'ejs' ).__express );
app.set('views', path.join(__dirname, '/app/views'));
app.use(express.static(path.join(__dirname, '/public')));
require('./app/routes/index')(app);

压缩前:

Name                Status          Type        Initiator       Size          Time
static.js           200             script      (index):2       135 KB        16 ms
vendors.js          200             script      (index):2       250 KB        18 ms
client.js           200             script      (index):2       111 KB        18 ms
login.e8c9aed7.js   200             script      static.js:1     6.5 KB        3 ms

压缩后:

Name                Status          Type        Initiator       Size          Time
static.js           200             script      (index):2       46.1 KB       16 ms
vendors.js          200             script      (index):2       67.9 KB       18 ms
client.js           200             script      (index):2       29.9 KB       18 ms
login.e8c9aed7.js   200             script      static.js:1     2.0 KB        3 ms

node.js + koa

执行命令下载包
npm install koa-gzip --save-dev

加载包

var gzip = require('koa-gzip');
app.use(gzip());

具体代码同上

单独node.js压缩方法

Koa 接受 Fetch Post数据

环境使用Koa v3版本 + node.js
Koa要接收POST的数据可以使用中间件koa-bodyparser
其他body库支持koa版本以及介绍

//设置
import bodyParser from 'koa-bodyparser';
app.use(bodyParser());

//调用
router.post('/indie/song/1', (ctx, next) => {
    console.log(ctx.request.body);
});

Jquery$.ajax()直接设置data参数即可.

Fetch参数可以设置body参数

fetch(url, {
    method: "post",
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    },
    body: 'title=test&sub%5B%5D=1&sub%5B%5D=2&sub%5B%5D=3'
})
    .then(e => e.json())
    .then(s => {
        console.log(s);
    });
注意!使用Fetch传参时需要设置headers,否则服务端无法接收

application/x-www-form-urlencoded

浏览器的原生 form 表单,如果不设置 enctype 属性,那么最终就会以 application/x-www-form-urlencoded 方式提交数据。提交的数据按照 key1=val1&key2=val2 的方式进行编码,key 和 val 都进行了 URL 转码。

POST http://www.123.com HTTP/1.1
Content-Type: application/x-www-form-urlencoded;charset=utf-8

title=test&sub%5B%5D=1&sub%5B%5D=2&sub%5B%5D=3

multipart/form-data

使用表单上传文件时,必须让 form 的 enctyped 等于这个值, 上传图片时,我们经常会看到下面这样

POST http://www.example.com HTTP/1.1
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryrGKCBY7qhFd3TrwA

------WebKitFormBoundaryrGKCBY7qhFd3TrwA
Content-Disposition: form-data; name="text"

title
------WebKitFormBoundaryrGKCBY7qhFd3TrwA
Content-Disposition: form-data; name="file"; filename="chrome.png"
Content-Type: image/png

PNG ... content of chrome.png ...
------WebKitFormBoundaryrGKCBY7qhFd3TrwA--

application/json

把它作为请求头,用来告诉服务端消息主体是序列化后的 JSON 字符串。但也有些服务端语言还没有支持这种方式,例如 php 就无法通过 $_POST 对象从上面的请求中获得内容。这时候,需要自己动手处理下:在请求头中 Content-Type 为 application/json 时,从 php://input 里获得原始输入流,再 json_decode 成对象。

`{"static": "true"}`

参考文章:

  1. Fetch POST接收不到数据,注意content-type的设置
  2. MDN fetch文档

webpack

getEntry(获取文件)

var getEntry = function (url) {
    var entry = {};
    glob.sync(url).forEach(function (name) {
        //循环所有文件,对文件名做处理,并放入entry数组中,返回entry
        if(name.indexOf('views') != -1){
            //是html页面
            var n = name.substring(13,name.lastIndexOf('.'));
        }else{
            //不是html页面  这里实际上只有js页面需要处理
            var n = name.substring((name.lastIndexOf('/') + 1),name.lastIndexOf('.'));
        }
        var name = __dirname + name.substring(1);
        if(n.indexOf('.') != 0){
            entry[n] = name;
        }
    });
    return entry;
};

html-webpack-plugin(html页面自动插入js/css)

var pages = getEntry('./gulp/views/**');

for(var chunkname in pages){
    var conf = {
        filename: 'html/'+chunkname+'.html',  //打包后的html存放路径,也是从distPath开始
        template: pages[chunkname], //文件模板,就是打包前的html文件
        inject: true, //可以对head和body做修改
        //设置该页面引用的文件,只有符合条件的才会被引用
        //这里是'common'和页面同名的js\css文件
        chunks : ['jquery','react','react-dom', chunkname.substring(chunkname.indexOf('/')+1)],
        //minify: { //压缩HTML,开启压缩可能会造成语法错误.无法解析后台模板变量如:"{{html}}"
          //  removeComments: true,
            //collapseWhitespace: false
        //},
        hash: true //版本号,打出来的html中对css和js的引用自带版本号
    };
    //把每个conf循环插入plugins
    plugins.push(new HtmlWebpackPlugin(conf));
}

整体配置

var path = require('path');
var webpack = require('webpack');
var build = require('./build.js');

var distPath = path.join(__dirname, '/public/dist/');

var plugins = [];

plugins.push(new webpack.optimize.UglifyJsPlugin({
        compress: {
            warnings: false
        },
        except: ['$', 'require']    //排除关键字,不然会把这些都压缩替换
    })
);

module.exports = {
    entry: build,
    output: {
        path: distPath,
        publicPath: "/public/dist/",
        filename: '[name].js'
    },
    module: {
        loaders: [
            {test: /\.js?$/, loaders: ['jsx?harmony']},
            {test: /\.html$/, loader: "html?-minimize"}
        ]
    },
    resolve: {
        alias: {
            jwplayer: __dirname+'/public/static/plugins/jwplayer-7.3.4/jwplayer.js',
            video: __dirname+'/components/video.js'
        }
    },
    externals: {
        "react": 'React',
        'react-dom': 'ReactDOM',
        'jwplayer': 'jwplayer'
    },
    plugins: plugins
};

npm install 失败(no-bin-links)

npm install node-jsx --save-dev

错误信息:

npm WARN EPACKAGEJSON [email protected] No repository field.
npm ERR! Linux 2.6.32-431.el6.i686
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "node-jsx" "--save-dev"
npm ERR! node v5.4.0
npm ERR! npm  v3.3.12
npm ERR! path ../acorn/bin/acorn
npm ERR! code EPROTO
npm ERR! errno -71
npm ERR! syscall symlink

npm ERR! EPROTO: protocol error, symlink '../acorn/bin/acorn' -> '/home/luoo/asd/node_modules/.bin/acorn'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>
npm ERR! Linux 2.6.32-431.el6.i686
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "node-jsx" "--save-dev"
npm ERR! node v5.4.0
npm ERR! npm  v3.3.12
npm ERR! path npm-debug.log.3a99b40993ded0f99040c95233b90c64
npm ERR! code ETXTBSY
npm ERR! errno -26
npm ERR! syscall rename

npm ERR! ETXTBSY: text file is busy, rename 'npm-debug.log.3a99b40993ded0f99040c95233b90c64' -> 'npm-debug.log'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /home/luoo/asd/npm-debug.log

可以使用--no-bin-links
npm install node-jsx --no-bin-links
bin-links from NPM docs:

Set to false to have it not do this. This can be used to work around the fact that some file systems don't support symlinks, even on ostensibly Unix systems.

ES6 Babel 编译器支持表

Babel

ES6特性 兼容性
箭头函数 支持
类的声明和继承 部分支持,IE8不支持
增强的对象字面量 支持
字符串模板 支持
解构 支持,但注意使用方式
参数默认值,不定参数,拓展参数 支持
let与const 支持
for of IE不支持
iterator, generator 不支持
模块 module、Proxies、Symbol 不支持
Map,Set 和 WeakMap,WeakSet 不支持
Promises、Math,Number,String,Object 的新API 不支持
export & import 支持
生成器函数 不支持
数组拷贝 支持

附上各编译器的支持情况表:
http://kangax.github.io/compat-table/es6/

CSS3 单行/多行溢出隐藏

单行

overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;

qq 20170717172316

多行

display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;

qq 20170717172316

/*强制不换行*/
white-space: nowrap;
/*强制换行*/
word-break: break-all;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.