Skip to content

Commit 78a0453

Browse files
committed
(chore) no longer bundle Vue.js plugin
1 parent bfa6600 commit 78a0453

File tree

6 files changed

+41
-8
lines changed

6 files changed

+41
-8
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,11 @@ div.code {
147147

148148
## Using with Vue.js
149149

150-
Simply register the plugin with Vue:
150+
Simply build & register the plugin with Vue:
151151

152152
```js
153-
Vue.use(hljs.vuePlugin);
153+
import { buildVuePlugin } from "highlight.js/lib/vue_plugin.js";
154+
Vue.use(buildVuePlugin(hljs).VuePlugin);
154155
```
155156

156157
And you'll be provided with a `highlightjs` component for use

src/highlight.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import * as utils from './lib/utils.js';
1212
import * as MODES from './lib/modes.js';
1313
import { compileLanguage } from './lib/mode_compiler.js';
1414
import * as packageJSON from '../package.json';
15-
import { BuildVuePlugin } from "./plugins/vue.js";
1615
import * as logger from "./lib/logger.js";
1716

1817
const escape = utils.escapeHTML;
@@ -898,9 +897,7 @@ const HLJS = function(hljs) {
898897
registerAliases,
899898
autoDetection,
900899
inherit,
901-
addPlugin,
902-
// plugins for frameworks
903-
vuePlugin: BuildVuePlugin(hljs).VuePlugin
900+
addPlugin
904901
});
905902

906903
hljs.debugMode = function() { SAFE_MODE = false; };

src/plugins/vue.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function hasValueOrEmptyAttribute(value) {
55
return Boolean(value || value === "");
66
}
77

8-
export function BuildVuePlugin(hljs) {
8+
export default function BuildVuePlugin(hljs) {
99
const Component = {
1010
props: ["language", "code", "autodetect"],
1111
data: function() {

tools/build_browser.js

+24
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ async function buildBrowser(options) {
5858

5959
detailedGrammarSizes(languages);
6060

61+
await buildVuePluginJS({ minify: options.minify });
6162
const size = await buildBrowserHighlightJS(languages, { minify: options.minify });
6263

6364
log("-----");
@@ -154,6 +155,29 @@ function installDemoStyles() {
154155
});
155156
}
156157

158+
async function buildVuePluginJS({ minify }) {
159+
log("Building vue_plugin.js.");
160+
161+
const outFile = `${process.env.BUILD_DIR}/vue_plugin.js`;
162+
const minifiedFile = outFile.replace(/js$/, "min.js");
163+
164+
const input = { ...config.rollup.browser_core.input, input: `src/plugins/vue.js`};
165+
const output = config.rollup.browser_core.output;
166+
// output.footer = output.footer.replace("hljs", "hljsVue");
167+
let pluginSrc = await rollupCode(input,
168+
{ ...output, file: outFile, name: "hljsVue", footer: null });
169+
170+
const tasks = [];
171+
tasks.push(fs.writeFile(outFile, pluginSrc, { encoding: "utf8" }));
172+
173+
if (minify) {
174+
const tersed = await Terser.minify(pluginSrc, config.terser);
175+
tasks.push(fs.writeFile(minifiedFile, tersed.code, { encoding: "utf8" }));
176+
}
177+
178+
await Promise.all(tasks);
179+
}
180+
157181
async function buildBrowserHighlightJS(languages, { minify }) {
158182
log("Building highlight.js.");
159183

tools/build_node.js

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ async function buildNodeLanguage(language) {
3434
await rollupWrite(input, output);
3535
}
3636

37+
async function buildNodeVuePluginJS() {
38+
const input = { ...config.rollup.node.input, input: `src/plugins/vue.js` };
39+
const output = { ...config.rollup.node.output, file: `${process.env.BUILD_DIR}/lib/vue_plugin.js` };
40+
await rollupWrite(input, output);
41+
}
42+
43+
3744
async function buildNodeHighlightJS() {
3845
const input = { ...config.rollup.node.input, input: `src/highlight.js` };
3946
const output = { ...config.rollup.node.output, file: `${process.env.BUILD_DIR}/lib/core.js` };
@@ -81,9 +88,11 @@ async function buildNode(options) {
8188

8289
await buildNodeIndex(languages);
8390
await buildLanguages(languages);
91+
await buildNodeVuePluginJS();
8492

8593
log("Writing highlight.js");
8694
await buildNodeHighlightJS();
95+
8796
}
8897

8998
module.exports.build = buildNode;

tools/developer.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ <h3>Markup</h3>
175175
</div>
176176

177177
<script src="../build/highlight.js"></script>
178+
<script src="../build/vue_plugin.js"></script>
178179
<script src="vendor/jquery-2.1.1.min.js"></script>
179180
<script src="vendor/vue.js"></script>
180181

@@ -273,7 +274,8 @@ <h3>Markup</h3>
273274
});
274275
}());
275276

276-
Vue.use(hljs.vuePlugin);
277+
let plugin = hljsVue(hljs).VuePlugin;
278+
Vue.use(plugin);
277279
let vue = new Vue({
278280
el: '#app',
279281
data: { code: "", language: "" },

0 commit comments

Comments
 (0)