question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing all languages in node.js

See original GitHub issue

This is related to: https://github.com/PrismJS/prism/issues/593

The components are injected when you require the module, so can we have (for the node users) an index.js inside components folder, that does this?

require './prism-abap.js';
require './prism-actionscript.js';
require './prism-apacheconf.js';
// ...

So then we only have to use:

import prismjs from 'prismjs';
import 'prismjs/components';

Or even something like:

function loadComponents(arr) {
  arr.foreach(function(language) {
    require('./prism-' + language);
  });
}

module.exports = loadComponents;
import prismjs from 'prismjs';
import loadComponents from 'prismjs/components';
loadComponents(['php', 'ruby']);

This won’t work in the browser i think, but why not have this simple helper for the node users?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

8reactions
Golmotecommented, Mar 20, 2018

Ok, we added a loadLanguages() function that can be used as suggested here:

var Prism = require('./components/prism-core.js');
var loadLanguages = require('./components/index.js');
loadLanguages(['php', 'ruby']);

Prism.highlight(...);

It will load the required dependencies.

I still need to document this somewhere. I’ll close the issue once it’s done.

4reactions
bradymholtcommented, Apr 18, 2019

I found that if you don’t specify an array of languages, all of them will be loaded.

In TypeScript, I was able to load all languages using this syntax:

import * as prism from 'prismjs';
require("prismjs/components/")();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js Tutorial on Creating a Multilingual Web App | Phrase
We are going to place all the language files inside this folder. Each of the files is in the JSON format, and their...
Read more >
Localization in Node.js and Express.js with i18n examples
Installing and configuring Node.js i18n and Node.js apps localization. How can your Express.js application support multiple languages.
Read more >
How to import all exports of a file as an object in Node.js
Here, In the root folder of “GFG-MODULES”, there are 3 files namely “index.html”, “index.js” and our “package.json” file along with these, it ...
Read more >
Languages with a NodeJS/CommonJS style module system
@svick Primarily the require function, which returns either a function or some other structured data. As opposed to 'import x from y' which ......
Read more >
Loading locale in NodeJS
Docs · GitHub; Languages icon ... Loading locale in NodeJS. Loading locale on demand. require('dayjs/locale/de') // import 'dayjs/locale/de' // ES 2015 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found