Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"presets": ["es2015"]
"presets": ["es2015"],
"plugins": ["transform-runtime"]
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@
},
"homepage": "https://github.com/imsun/gitment",
"scripts": {
"build": "babel src --out-dir dist --ignore test.js --source-maps & NODE_ENV=production webpack --config webpack.config.js --progress --profile --colors",
"dev": "webpack-dev-server --config webpack.dev.config.js --host 0.0.0.0 --progress --profile --colors"
"build": "babel src --out-dir dist --ignore test.js --source-maps & cross-env NODE_ENV=production webpack --config webpack.config.js --progress --profile --colors",
"dev": "webpack-dev-server --config webpack.dev.config.js --host 0.0.0.0 --progress --profile --colors",
"postbuild": "babel src --out-dir dist --ignore test.js --source-maps & webpack --config webpack.config.js -p --env.production"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有理解为什么需要 postbuild。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样的话可以使用npm run build完成后自动生成压缩版本的gitment,当然可以直接生成压缩版本,但是为了不改动太大,所以就保留了你原有的脚本,在原有基础上添加

Copy link
Copy Markdown
Owner

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,压不压缩意义不大。不过加了我也没有意见。

},
"devDependencies": {
"babel-cli": "^6.24.0",
"babel-core": "^6.24.0",
"babel-loader": "^6.4.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.0",
"cross-env": "^5.0.1",
"webpack": "^2.3.2",
"webpack-dev-server": "^2.4.2"
},
"dependencies": {
"babel-runtime": "^6.23.0",
"mobx": "^3.1.7"
},
"license": "MIT"
Expand Down
9 changes: 5 additions & 4 deletions src/theme/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function renderHeader({ meta, user, reactions }, instance) {
likeButton.classList.remove('liked')
likeButton.onclick = () => instance.like()
}

container.appendChild(likeButton)

const commentsCount = document.createElement('span')
Expand Down Expand Up @@ -335,10 +336,10 @@ function render(state, instance) {
const container = document.createElement('div')
container.lang = "en-US"
container.className = 'gitment-container gitment-root-container'
container.appendChild(instance.renderHeader(state, instance))
container.appendChild(instance.renderComments(state, instance))
container.appendChild(instance.renderEditor(state, instance))
container.appendChild(instance.renderFooter(state, instance))
container.appendChild(renderHeader(state, instance))
container.appendChild(renderComments(state, instance))
container.appendChild(renderEditor(state, instance))
container.appendChild(renderFooter(state, instance))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

默认渲染函数之所以用 instance 调用渲染函数,是为了方便自定义主题。

比如一个人想自定义一下 footer,那他只要写一个 { renderFooter: () => { /* ... */} } 设为主题就好了,而不用将其他所有部分的逻辑都写一遍。自定义的 renderFooter 会覆盖 instance 上默认的 renderFooter 进行渲染。

return container
}

Expand Down
42 changes: 22 additions & 20 deletions webpack.config.js
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',

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还没加 lint。所以请手动在 operator 间补下空格。

(env && env.production) ? 'gitment.browser.min.js' : 'gitment.browser.js'

libraryTarget: 'var',
library: 'Gitment',
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loaders: ['babel-loader'],
},
],
},
}
};