在利用webpack2作为构建工具打包Angular4时,出现一个问题就是有两个文件打包出来的哈希值不变。

文件如下:

1
2
'common': './node_modules/moment/moment.js',
'polyfills': `./client/${platform}/polyfills.browser.ts`,

这两个文件,一个是服务于moment这个时间类库,一个是服务于处理SPA应用的浏览器兼容性问题,这两个文件,在webpack配置文件中我的配置方式如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Options affecting the output of the compilation.
*
* See: http://webpack.github.io/docs/configuration.html#output
*/
output: {

/**
* The output directory as absolute path (required).
*
* See: http://webpack.github.io/docs/configuration.html#output-path
*/
path: helpers.root('dist'),

/**
* Specifies the name of each output file on disk.
* IMPORTANT: You must not specify an absolute path here!
*
* See: http://webpack.github.io/docs/configuration.html#output-filename
*/
filename: '[name].[chunkhash].bundle.js',

/**
* The filename of the SourceMaps for the JavaScript files.
* They are inside the output.path directory.
*
* See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
*/
sourceMapFilename: '[name].[chunkhash].bundle.map',

/**
* The filename of non-entry chunks as relative path
* inside the output.path directory.
*
* See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
*/
chunkFilename: '[id].[chunkhash].chunk.js'

},

阅读全文 »

还有ionicv4?

ionic官方仓库已经创建了v4分支,也给出了v4的介绍及愿景,这里我翻一下,想看原文点击这里

翻译

ionic组件向着以下目标发展

  • 用户继续用angular组件开发APP和组件
  • 开发和构建不会有变化
  • 用户使用上的改变将会最小化
  • 减少构建时间
  • 减少启动时间
  • ionic组件的异步加载将会成为缺省配置
阅读全文 »

What is git and why should I use it? - Quora

想玩好Github开源项目,不懂Git不行,所以这里记录下,在使用中,用到的一些命令,方便自己以后去反复记忆,同时也希望能帮到一些朋友。
主要的命令记住,方便操作,其余的会查询即可。
以实际例子来说明,我在实际使用中用到的一些命令

Getting and Creating Projects

1
2
3
4
5
6
7
8
# 创建一个空的Git仓库,或者对于已存在的仓库,进行重初始化
git init

# 配置
git config [--global] user.name "alanhg"
git config [--global] user.email "i@xx.x"

git config --global --add push.default current
阅读全文 »

查看expressAPI
对于文件下载,最简单的实现下载方法为如下

1
2
3
4
5
6
7
8
9
res.download('/report-12345.pdf', 'report.pdf', function(err){
if (err) {
// Handle error, but keep in mind the response may be partially-sent
// so check res.headersSent
} else {
// decrement a download credit, etc.
}
});

但是这种方法在实际使用中,发现了问题,那就是苹果safari浏览器在下载时候,文件标题会自动截取一段,或者乱码,或者问号,
一开始表示不解,IE都没事,利用fiddler进行抓包分析,发现res头部信息不对劲儿,存在两个filename,也就是不同浏览器对于重复filename处理,不一样,或者说safari对于重复filename会有问题,也就是res.download的写法毕竟是高度封装的,
换句话说,不要用这种高度封装的写法就好了,那么如何解决呢。
如下一种写法,这种没有高度封装,自己去写返回头部信息,经测试Safari下载果然没问题了。

1
2
3
4
5
6
7
8
let filename = "你好,地球人你好,地球人你好,地球人你好,地球人.pdf";
let filePath = path.resolve(__dirname, '..') + '/static/pdf/test.pdf';
let mimetype = mime.lookup(filePath);
res.setHeader('Content-Disposition', 'attachment; filename=' + new Buffer(filename).toString('binary'));
res.setHeader('Content-type', mimetype);
let filestream = fs.createReadStream(filePath);
filestream.pipe(res);

对比发现,写法1比写法2简单的多,但是目前对于Safari、IE支持是不好的,如果直接用写法2,Edge又会有问题,这时又要牵扯对于不同浏览器,文件名中英文一堆的逻辑判断处理,
所以最好的解决办法是根据请求头部,对应处理下。
对于浏览器判别可以用下面的类库

阅读全文 »
0%