Skip to content

Commit e09409f

Browse files
committed
Optimize hljs size
1 parent 779ea1f commit e09409f

File tree

6 files changed

+109
-4
lines changed

6 files changed

+109
-4
lines changed

.babelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
["env", { "modules": false }],
4+
"stage-3"
5+
]
6+
}

package-lock.json

Lines changed: 81 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"vue-loader": "^13.0.5",
5151
"vue-template-compiler": "^2.4.4",
5252
"webpack": "^3.6.0",
53+
"webpack-bundle-analyzer": "^2.9.2",
5354
"webpack-dev-server": "^2.9.1"
5455
}
5556
}

src/components/plugin/Highlight.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* eslint-disable */
2+
import hljs from 'highlight.js/lib/highlight'
3+
import cpp from 'highlight.js/lib/languages/cpp'
4+
5+
window.hljs = hljs
6+
hljs.registerLanguage('cpp', cpp)
7+
8+
export default hljs

src/components/plugin/MarkdownParser.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'highlight.js/styles/atom-one-light.css'
2+
import Highlight from './Highlight'
23

34
export function MarkdownParser (code, stringMap) {
45
let marked = require('marked')
@@ -10,7 +11,7 @@ export function MarkdownParser (code, stringMap) {
1011
}
1112

1213
let highlight = function (code) {
13-
return require('highlight.js').highlightAuto(code).value
14+
return Highlight.highlightAuto(code).value
1415
}
1516

1617
renderer.code = function (code, lang, escaped) {

webpack.config.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
var path = require('path')
2-
var webpack = require('webpack')
1+
const path = require('path')
2+
const webpack = require('webpack')
33
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
44
const CleanWebpackPlugin = require('clean-webpack-plugin')
5+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
56

67
module.exports = {
78
entry: ["babel-polyfill",'./src/main.js'],
@@ -12,6 +13,7 @@ module.exports = {
1213
},
1314
plugins: [
1415
new LodashModuleReplacementPlugin(),
16+
new webpack.optimize.OccurrenceOrderPlugin(),
1517
new CleanWebpackPlugin(['dist'])
1618
],
1719
module: {
@@ -49,7 +51,7 @@ module.exports = {
4951
},
5052
resolve: {
5153
alias: {
52-
'vue$': 'vue/dist/vue.esm.js'
54+
'vue$': 'vue/dist/vue.runtime.esm.js'
5355
},
5456
extensions: ['*', '.js', '.vue', '.json']
5557
},
@@ -64,6 +66,12 @@ module.exports = {
6466
devtool: '#eval-source-map'
6567
}
6668

69+
if (process.env.BUNDLE_ANALYZE === 'true') {
70+
module.exports.plugins = (module.exports.plugins || []).concat([
71+
new BundleAnalyzerPlugin()
72+
])
73+
}
74+
6775
if (process.env.NODE_ENV === 'production') {
6876
module.exports.devtool = '#source-map'
6977
// http://vue-loader.vuejs.org/en/workflow/production.html

0 commit comments

Comments
 (0)