Skip to content
This repository was archived by the owner on Jan 27, 2021. It is now read-only.

Commit c0c09e3

Browse files
committed
style(device.js): optimize the way of including the device.js
Now device.js will be install every since you run `npm install`, and it the latest version will be compressed by using `npm run rel`. fix #35
1 parent 9af1927 commit c0c09e3

File tree

10 files changed

+108
-28
lines changed

10 files changed

+108
-28
lines changed

dist/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dev.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<canvas id="live2dcanvas" width="680" height="940" style="border:dashed 1px #CCC">
1212
</canvas>
1313
</div>
14-
<script type="text/javascript" src="bundle.js?157d51a75370887b7316"></script></body>
14+
<script type="text/javascript" src="device.min.js"></script>
15+
<script type="text/javascript" src="bundle.js?67a701d572040c6adaac"></script></body>
1516
</html>
1617
<!-- loadlive2d("live2dcanvas", "../assets/name/name.model.json", 0.5); -->

dist/device.min.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,28 @@ hexo.extend.helper.register('live2d', function() {
8787
`
8888
});
8989

90+
// 复制live2d模型文件
91+
// 先在 博客目录/live2d_models/ 目录下寻找
9092
fs.exists(path.resolve(hexo.base_dir, path.join('./live2d_models/', config.model)), function(exists){
9193
if(exists){
9294
registerDir("live2d/assets/", path.resolve(hexo.base_dir, path.join('./live2d_models/', config.model)));
93-
}else{
94-
registerDir('live2d/assets/', path.resolve(__dirname, path.join('./assets/', config.model)));
95+
}else{ // 若未找到,在 插件目录/assets/ 下继续寻找
96+
registerDir('live2d/assets/', path.resolve(__dirname, path.join('./assets/', config.model)));
9597
}
9698
});
9799

100+
// 复制 live2d客户端 脚本
98101
registerFile('live2d/script.js', path.resolve(__dirname, './dist/bundle.js'));
99-
registerFile('live2d/script.js.map', path.resolve(__dirname, './dist/bundle.js.map'));
100-
registerFile('live2d/device.min.js', path.resolve(__dirname, './dist/device.min.js'));
102+
103+
// 复制 device.js 脚本
104+
fs.exists(path.resolve(__dirname, './dist/device.min.js'), function(exists){
105+
if(exists){
106+
registerFile('live2d/device.min.js', path.resolve(__dirname, './dist/device.min.js'));
107+
}else{
108+
console.log("live2d serverJs can't find device.js");
109+
return ;
110+
}
111+
});
101112

102113
hexo.extend.generator.register('live2d', function (locals) {
103114
return generators;

package-lock.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"babel-preset-env": "^1.6.1",
1111
"commitizen": "^2.9.6",
1212
"cz-conventional-changelog": "^2.1.0",
13+
"device.js": "git+ssh://git@github.com/matthewhudson/device.js.git",
1314
"html-webpack-plugin": "^2.30.1",
1415
"source-map-loader": "^0.2.3",
1516
"uglify-js": "^3.1.9",
@@ -23,20 +24,34 @@
2324
"devenv": "npm install -g commitizen&&npm install -g cz-conventional-changelog&&npm install -g webpack&&npm install -g conventional-changelog-cli&&npm install",
2425
"dev": "webpack --config webpack.config.dev.js",
2526
"devw": "webpack --config webpack.config.dev.js -w",
26-
"rel": "webpack",
27+
"rel": "webpack --config webpack.config.device.js&&webpack",
2728
"commit": "git-cz",
2829
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
2930
"test": "echo \"Nothing here, but someday there will be something here. xD\" && exit 1"
3031
},
31-
"author": "EYHN",
32+
"author": {
33+
"name": "EYHN",
34+
"email": "cneyhn@gmail.com"
35+
},
36+
"contributors": [
37+
{
38+
"name": "xiazeyu",
39+
"email": "xiazeyu_2011@126.com"
40+
}
41+
],
42+
"maintainers": [
43+
{
44+
"name": "xiazeyu",
45+
"email": "xiazeyu_2011@126.com"
46+
}
47+
],
3248
"license": "GPL-2.0",
3349
"repository": {
3450
"type": "git",
35-
"url": "https://github.com/EYHN/hexo-helper-live2d.git"
51+
"url": "git://github.com/EYHN/hexo-helper-live2d.git"
3652
},
3753
"bugs": {
38-
"url": "https://github.com/EYHN/hexo-helper-live2d/issues",
39-
"email": "cneyhn@gmail.com"
54+
"url": "https://github.com/EYHN/hexo-helper-live2d/issues"
4055
},
4156
"homepage": "https://github.com/EYHN/hexo-helper-live2d#readme",
4257
"config": {

src/dev.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<canvas id="live2dcanvas" width="680" height="940" style="border:dashed 1px #CCC">
1212
</canvas>
1313
</div>
14+
<script type="text/javascript" src="device.min.js"></script>
1415
</body>
1516
</html>
1617
<!-- loadlive2d("live2dcanvas", "../assets/name/name.model.json", 0.5); -->

webpack.config.dev.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ module.exports = {
2222
devtool: "source-map",
2323

2424
plugins: [
25-
new HtmlWebpackPlugin(HtmlWebpackConfig),
25+
new webpack.DefinePlugin({
26+
'process.env': {
27+
NODE_ENV: '"production"'
28+
}
29+
}),
2630
new webpack.optimize.UglifyJsPlugin({
27-
compress: {
28-
warnings: true
29-
},
31+
compress: true,
32+
warnings: true,
3033
sourceMap: true,
31-
mangle: false
32-
})
34+
mangle: true
35+
}),
36+
new HtmlWebpackPlugin(HtmlWebpackConfig)
3337
],
3438

3539
resolve: {

webpack.config.device.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
var webpack = require('webpack');
2+
var path = require('path')
3+
var uglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
4+
5+
module.exports = {
6+
entry: [
7+
"./node_modules/device.js/lib/device.js"
8+
],
9+
output: {
10+
filename: "device.min.js",
11+
path: __dirname + "/dist"
12+
},
13+
14+
plugins: [
15+
new webpack.DefinePlugin({
16+
'process.env': {
17+
NODE_ENV: '"production"'
18+
}
19+
}),
20+
new webpack.optimize.UglifyJsPlugin({
21+
compress: true,
22+
warnings: true,
23+
sourceMap: false,
24+
mangle: true
25+
})
26+
],
27+
28+
resolve: {
29+
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
30+
},
31+
32+
module: {
33+
rules: [
34+
{
35+
test: /\.js$/,
36+
exclude: path.resolve(__dirname, "node_modules"),
37+
use: [{
38+
loader: 'babel-loader',
39+
query: {
40+
presets: ["env"]
41+
}
42+
}],
43+
}
44+
]
45+
}
46+
}

webpack.config.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@ module.exports = {
2020
},
2121

2222
plugins: [
23-
new HtmlWebpackPlugin(HtmlWebpackConfig),
24-
new webpack.optimize.UglifyJsPlugin({
25-
compress: {
26-
warnings: true
27-
},
28-
sourceMap: false,
29-
mangle: true
30-
}),
3123
new webpack.DefinePlugin({
3224
'process.env': {
3325
NODE_ENV: '"production"'
3426
}
35-
})
27+
}),
28+
new webpack.optimize.UglifyJsPlugin({
29+
compress: true,
30+
warnings: true,
31+
sourceMap: false,
32+
mangle: true
33+
}),
34+
new HtmlWebpackPlugin(HtmlWebpackConfig)
3635
],
3736

3837
resolve: {

0 commit comments

Comments
 (0)