Browse Source

Exclude unused hljs languages from bundle

pull/222/head
Clemens Wolff 5 years ago
parent
commit
7151015a49
3 changed files with 16 additions and 1 deletions
  1. 1
      app/server/static/components/hljsLanguages.js
  2. 10
      app/server/static/components/uploadMixin.js
  3. 6
      app/server/static/webpack.config.js

1
app/server/static/components/hljsLanguages.js

@ -0,0 +1 @@
module.exports = ['json'];

10
app/server/static/components/uploadMixin.js

@ -1,7 +1,15 @@
import hljs from 'highlight.js';
import hljs from 'highlight.js/lib/highlight';
import hljsLanguages from './hljsLanguages';
import HTTP, { newHttpClient } from './http';
import Messages from './messages.vue';
hljsLanguages.forEach((languageName) => {
/* eslint-disable import/no-dynamic-require, global-require */
const languageModule = require(`highlight.js/lib/languages/${languageName}`);
/* eslint-enable import/no-dynamic-require, global-require */
hljs.registerLanguage(languageName, languageModule);
});
export default {
components: { Messages },

6
app/server/static/webpack.config.js

@ -3,6 +3,8 @@ const path = require('path');
const process = require('process');
const BundleTracker = require('webpack-bundle-tracker');
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const { ContextReplacementPlugin } = require('webpack');
const hljsLanguages = require('./components/hljsLanguages');
const devMode = process.env.DEBUG !== 'False';
const hotReload = process.env.HOT_RELOAD === '1';
@ -58,6 +60,10 @@ module.exports = {
]
},
plugins: [
new ContextReplacementPlugin(
/highlight\.js\/lib\/languages$/,
new RegExp(`^./(${hljsLanguages.join('|')})$`)
),
new BundleTracker({ filename: './webpack-stats.json' }),
new VueLoaderPlugin()
],

Loading…
Cancel
Save