Load ot without script-loader

The ot library is tricky to load with Webpack, as it writes
it's functions into a global `ot` object and does not export anything.
I got it working using `exports-loader` to put the `ot` object
into a CommonJS export and then forcing Webpack to only
load using CommonJS.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren
2021-06-06 18:17:52 +02:00
parent 4f4a4cb747
commit bd62e79f7d
4 changed files with 27 additions and 11 deletions

View File

@@ -214,7 +214,6 @@ module.exports = {
index: [
'babel-polyfill',
'expose-loader?exposes=LZString!lz-string',
'script-loader!ot',
'flowchart.js',
'js-sequence-diagrams',
'expose-loader?exposes=RevealMarkdown!reveal-markdown',
@@ -256,7 +255,6 @@ module.exports = {
'expose-loader?exposes=emojify!emojify.js',
'script-loader!gist-embed',
'expose-loader?exposes=LZString!lz-string',
'script-loader!ot',
'flowchart.js',
'js-sequence-diagrams',
'expose-loader?exposes=Viz!viz.js',
@@ -350,7 +348,6 @@ module.exports = {
modules: ['node_modules'],
extensions: ['.js'],
alias: {
ot: path.join(__dirname, 'public/vendor/ot/ot.min.js'),
mermaid: path.join(__dirname, 'node_modules/mermaid/dist/mermaid.min.js'),
handlebars: path.join(__dirname, 'node_modules/handlebars/dist/handlebars.min.js'),
'gist-embed': path.join(__dirname, 'node_modules/gist-embed/gist-embed.min.js'),
@@ -382,6 +379,19 @@ module.exports = {
}
}
},
{
test: require.resolve(path.join(__dirname, 'public/vendor/ot/ot.min.js')),
use: {
loader: 'exports-loader',
options: {
type: 'commonjs',
exports: ['ot']
}
},
parser: {
amd: false
}
},
{
// Idle.js must be imported as CommonJS, as its AMD export is broken
test: require.resolve('Idle.Js'),