Skip to content

Commit cc2201d

Browse files
committed
refactor: migrate to ES modules and update webpack config for markmap and yaml support
Signed-off-by: Yukai Huang <[email protected]>
1 parent 300f11c commit cc2201d

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

babel.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module.exports = {
55
node: '14'
66
},
77
useBuiltIns: 'usage',
8-
corejs: 3
8+
corejs: 3,
9+
modules: 'auto'
910
}]
1011
],
1112
plugins: [

public/js/render.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-env browser, jquery */
22
// allow some attributes
33

4-
var filterXSS = require('xss')
4+
import filterXSS from 'xss'
55

66
var whiteListAttr = ['id', 'class', 'style']
77
window.whiteListAttr = whiteListAttr
@@ -72,7 +72,5 @@ function preventXSS (html) {
7272
}
7373
window.preventXSS = preventXSS
7474

75-
module.exports = {
76-
preventXSS: preventXSS,
77-
escapeAttrValue: filterXSS.escapeAttrValue
78-
}
75+
export { preventXSS }
76+
export const escapeAttrValue = filterXSS.escapeAttrValue

public/js/reveal-markdown.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { md } from './extra'
1616
root.RevealMarkdown = factory()
1717
root.RevealMarkdown.initialize()
1818
}
19-
}(this, function () {
19+
}(typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : this, function () {
2020
var DEFAULT_SLIDE_SEPARATOR = '^\r?\n---\r?\n$'
2121
var DEFAULT_NOTES_SEPARATOR = '^note:'
2222
var DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = '\\.element\\s*?(.+?)$'

webpack.common.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ module.exports = {
422422

423423
resolve: {
424424
modules: ['node_modules'],
425-
extensions: ['.js'],
425+
extensions: ['.js', '.mjs'],
426426
alias: {
427427
codemirror: path.join(__dirname, 'node_modules/@hackmd/codemirror/codemirror.min.js'),
428428
inlineAttachment: path.join(__dirname, 'public/vendor/inlineAttachment/inline-attachment.js'),
@@ -464,17 +464,39 @@ module.exports = {
464464
type: 'javascript/auto',
465465
include: /node_modules/
466466
}, {
467-
test: /node_modules\/markmap-[^/]+\/.*\.mjs$/,
468-
use: [{ loader: 'babel-loader' }]
467+
test: /node_modules\/markmap.*\/.*\.mjs$/,
468+
use: [{ loader: 'babel-loader' }],
469+
type: 'javascript/auto'
469470
}, {
470-
test: /node_modules\/markmap-[^/]+\/.*\.js$/,
471-
use: [{ loader: 'babel-loader' }]
471+
test: /node_modules\/markmap.*\/.*\.js$/,
472+
use: [{
473+
loader: 'babel-loader',
474+
options: {
475+
presets: [
476+
['@babel/preset-env', {
477+
modules: 'cjs'
478+
}]
479+
]
480+
}
481+
}]
472482
}, {
473483
test: /node_modules\/yaml\/browser\/dist\/.*\.js$/,
474484
use: [{ loader: 'babel-loader' }]
475485
}, {
476486
test: /node_modules\/@vscode\/markdown-it-katex\/.*\.js$/,
477-
use: [{ loader: 'babel-loader' }]
487+
use: [{
488+
loader: 'babel-loader',
489+
options: {
490+
presets: [
491+
['@babel/preset-env', {
492+
modules: 'cjs'
493+
}]
494+
],
495+
plugins: [
496+
'@babel/plugin-transform-optional-chaining'
497+
]
498+
}
499+
}]
478500
}, {
479501
test: /\.js$/,
480502
use: [{ loader: 'babel-loader' }],

0 commit comments

Comments
 (0)