-
Notifications
You must be signed in to change notification settings - Fork 350
提高gitment的浏览器兼容性 #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
提高gitment的浏览器兼容性 #52
Changes from 6 commits
bd261e7
aa7c305
ffa970e
9fdfef5
bdd45fe
1c68090
54af3cb
2f9a7ba
f0e2a0b
50ff9dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| { | ||
| "presets": ["es2015"] | ||
| "presets": ["es2015"], | ||
| "plugins": ["transform-runtime"] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,7 @@ const scope = 'public_repo' | |
| function extendRenderer(instance, renderer) { | ||
| instance[renderer] = (container) => { | ||
| const targetContainer = getTargetContainer(container) | ||
| const render = instance.theme[renderer] || instance.defaultTheme[renderer] | ||
|
|
||
| const render = instance.theme[renderer] | ||
| autorun(() => { | ||
| const e = render(instance.state, instance) | ||
| if (targetContainer.firstChild) { | ||
|
|
@@ -46,20 +45,17 @@ class Gitment { | |
|
|
||
| constructor(options = {}) { | ||
| this.defaultTheme = defaultTheme | ||
| this.useTheme(defaultTheme) | ||
|
|
||
| Object.assign(this, { | ||
| id: window.location.href, | ||
| title: window.document.title, | ||
| link: window.location.href, | ||
| desc: '', | ||
| labels: [], | ||
| theme: defaultTheme, | ||
| oauth: {}, | ||
| perPage: 20, | ||
| maxCommentHeight: 250, | ||
| }, options) | ||
|
|
||
| this.theme = Object.assign({},defaultTheme,options.theme); | ||
|
||
| this.useTheme(this.theme) | ||
|
|
||
| const user = {} | ||
|
|
@@ -127,10 +123,9 @@ class Gitment { | |
| } | ||
|
|
||
| useTheme(theme = {}) { | ||
| this.theme = theme | ||
|
|
||
| const renderers = Object.keys(this.theme) | ||
| renderers.forEach(renderer => extendRenderer(this, renderer)) | ||
| const renderers = Object.keys(theme) | ||
| renderers.forEach(renderer => this[renderer]=this.theme[renderer]) | ||
| extendRenderer(this,'render') | ||
|
||
| } | ||
|
|
||
| update() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,24 @@ | ||
| const path = require('path') | ||
|
|
||
| module.exports = { | ||
| context: path.join(__dirname, 'src'), | ||
| entry: './gitment.js', | ||
| devtool: 'source-map', | ||
| output: { | ||
| path: path.join(__dirname, 'dist'), | ||
| filename: 'gitment.browser.js', | ||
| libraryTarget: 'var', | ||
| library: 'Gitment', | ||
| }, | ||
| module: { | ||
| loaders: [ | ||
| { | ||
| test: /\.js$/, | ||
| exclude: /^node_mocules/, | ||
| loaders: ['babel-loader'], | ||
| }, | ||
| ], | ||
| }, | ||
| } | ||
| module.exports = function (env) { | ||
| return { | ||
| context: path.join(__dirname, 'src'), | ||
| entry: './gitment.js', | ||
| devtool: 'source-map', | ||
| output: { | ||
| path: path.join(__dirname, 'dist'), | ||
| filename: (env&&env.production)?'gitment.browser.min.js':'gitment.browser.js', | ||
|
||
| libraryTarget: 'var', | ||
| library: 'Gitment', | ||
| }, | ||
| module: { | ||
| loaders: [ | ||
| { | ||
| test: /\.js$/, | ||
| exclude: /node_modules/, | ||
| loaders: ['babel-loader'], | ||
| }, | ||
| ], | ||
| }, | ||
| } | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有理解为什么需要 postbuild。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这样的话可以使用
npm run build完成后自动生成压缩版本的gitment,当然可以直接生成压缩版本,但是为了不改动太大,所以就保留了你原有的脚本,在原有基础上添加There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个和 postbuild 的语义不大相符。而且 postbuild 是接着 build 执行的, 前半段命令在 build 时已经执行过了,没有必要再执行一遍。另外我也不建议通过
env.production做标识来判断是否需要压缩,因为已经有NODE_ENV了,都是 production 语义上却有分歧。如果加压缩应该在 build 脚本里同时 build 出两个文件。至于展开来说,我当时没加压缩主要是因为现在的 server 都开了 gzip,压不压缩意义不大。不过加了我也没有意见。