Closed jcubic closed 7 months ago
Did you try adding these extensions to auto-mode-alist
?
See also web-mode-content-types-alist
.
auto-mode-alist will not help since this only triggers the major mode of different file types. This is the same as triggering the mode manually. The mode is enabled, only everything is white (in dark mode).
Not sure how to use the second one, there is only a default value that I don't understand:
(setq web-mode-content-types-alist
’(("json" . "/some/path/.*\.api\’")
("jsx" . "/some/react/path/.*\.js[x]?\’")))
I've found this variable web-mode-engines-alist
and used this code:
(add-to-list 'auto-mode-alist '("\\.mjs\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.cjs\\'" . web-mode))
(dolist (spec '(("js" . "\\.mjs\\'")
("js" . "\\.cjs\\'")))
(add-to-list 'web-mode-engines-alist spec))
But this doesn't work. Also tried:
(dolist (spec '(("javascript" . "\\.mjs\\'")
("javascript" . "\\.cjs\\'")))
(add-to-list 'web-mode-engines-alist spec))
That also doesn't work.
This seems to work:
(add-to-list 'auto-mode-alist '("\\.mjs\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.cjs\\'" . web-mode))
(dolist (spec '(("javascript" . "\\.mjs\\'")
("javascript" . "\\.cjs\\'")))
(add-to-list 'web-mode-content-types-alist spec))
with NodeJS there are new types of file extensions:
mjs
forES Modules
having this extension NodeJS will run JavaScript as a module, and there is alsocjs
for forcing common JS type of module.Both file extensions don't work with Web-mode.
Is there a way to force web-mode to think that the file is actually JavaScript? I only tested manually triggering the web-mode with
M-x
.