Implement code splitting for codemirror
This commit is contained in:
1 parent
f79b9dc0f7
commit
de759b8d93
7 files changed
+48
-6
No files matched your search
@@ -2,7 +2,9 @@
|
|||||||
"env": {
|
"env": {
|
||||||
"browser": true
|
"browser": true
|
||||||
},
|
},
|
||||||
|
"parser": "babel-eslint",
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
|
"allowImportExportEverywhere": true,
|
||||||
"sourceType": "module",
|
"sourceType": "module",
|
||||||
"ecmaVersion": 8
|
"ecmaVersion": 8
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import m from "mithril";
|
import m from "mithril";
|
||||||
import { fromTextArea as codeMirrorFromTextArea } from "codemirror";
|
import { codeMirror } from "../dynamic-loader";
|
||||||
import "codemirror/mode/javascript/javascript";
|
|
||||||
|
|
||||||
const singular = {
|
const singular = {
|
||||||
presets: "preset",
|
presets: "preset",
|
||||||
@@ -41,7 +40,7 @@ function createField(current, attr, focus) {
|
|||||||
name: attr.id,
|
name: attr.id,
|
||||||
value: current.object[attr.id],
|
value: current.object[attr.id],
|
||||||
oncreate: _vnode => {
|
oncreate: _vnode => {
|
||||||
let editor = codeMirrorFromTextArea(_vnode.dom, {
|
let editor = codeMirror.fromTextArea(_vnode.dom, {
|
||||||
mode: "javascript",
|
mode: "javascript",
|
||||||
lineNumbers: true
|
lineNumbers: true
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
let codeMirror;
|
||||||
|
|
||||||
|
function loadCodeMirror() {
|
||||||
|
if (codeMirror) return Promise.resolve();
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const promises = [
|
||||||
|
import(/* webpackChunkName: "codemirror" */ "codemirror"),
|
||||||
|
import(/* webpackChunkName: "codemirror" */ "codemirror/mode/javascript/javascript")
|
||||||
|
];
|
||||||
|
Promise.all(promises)
|
||||||
|
.then(modules => {
|
||||||
|
codeMirror = modules[0];
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export { loadCodeMirror, codeMirror };
|
||||||
@@ -12,6 +12,7 @@ import putForm from "./components/put-form";
|
|||||||
import * as overlay from "./overlay";
|
import * as overlay from "./overlay";
|
||||||
import * as smartQuery from "./smart-query";
|
import * as smartQuery from "./smart-query";
|
||||||
import * as expressionParser from "../common/expression-parser";
|
import * as expressionParser from "../common/expression-parser";
|
||||||
|
import { loadCodeMirror } from "./dynamic-loader";
|
||||||
|
|
||||||
const PAGE_SIZE = config.ui.pageSize || 10;
|
const PAGE_SIZE = config.ui.pageSize || 10;
|
||||||
|
|
||||||
@@ -106,7 +107,14 @@ function init(args) {
|
|||||||
|
|
||||||
const sort = args.sort;
|
const sort = args.sort;
|
||||||
const filter = args.filter;
|
const filter = args.filter;
|
||||||
return Promise.resolve({ filter, sort });
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
loadCodeMirror()
|
||||||
|
.then(() => {
|
||||||
|
resolve({ filter, sort });
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderTable(
|
function renderTable(
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import putForm from "./components/put-form";
|
|||||||
import * as overlay from "./overlay";
|
import * as overlay from "./overlay";
|
||||||
import * as smartQuery from "./smart-query";
|
import * as smartQuery from "./smart-query";
|
||||||
import * as expressionParser from "../common/expression-parser";
|
import * as expressionParser from "../common/expression-parser";
|
||||||
|
import { loadCodeMirror } from "./dynamic-loader";
|
||||||
|
|
||||||
const PAGE_SIZE = config.ui.pageSize || 10;
|
const PAGE_SIZE = config.ui.pageSize || 10;
|
||||||
|
|
||||||
@@ -106,7 +107,14 @@ function init(args) {
|
|||||||
|
|
||||||
const sort = args.sort;
|
const sort = args.sort;
|
||||||
const filter = args.filter;
|
const filter = args.filter;
|
||||||
return Promise.resolve({ filter, sort });
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
loadCodeMirror()
|
||||||
|
.then(() => {
|
||||||
|
resolve({ filter, sort });
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderTable(
|
function renderTable(
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
"parsimmon": "^1.12.0"
|
"parsimmon": "^1.12.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"babel-eslint": "^8.2.6",
|
||||||
"clean-webpack-plugin": "^0.1.19",
|
"clean-webpack-plugin": "^0.1.19",
|
||||||
"copy-webpack-plugin": "^4.5.2",
|
"copy-webpack-plugin": "^4.5.2",
|
||||||
"cssnano": "^4.0.5",
|
"cssnano": "^4.0.5",
|
||||||
|
|||||||
+3
-1
@@ -1,6 +1,7 @@
|
|||||||
const nodeExternals = require("webpack-node-externals");
|
const nodeExternals = require("webpack-node-externals");
|
||||||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||||
const CleanWebpackPlugin = require("clean-webpack-plugin");
|
const CleanWebpackPlugin = require("clean-webpack-plugin");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
const mode = "production";
|
const mode = "production";
|
||||||
|
|
||||||
@@ -51,7 +52,8 @@ module.exports = [
|
|||||||
mode: mode,
|
mode: mode,
|
||||||
entry: "./client/app.js",
|
entry: "./client/app.js",
|
||||||
output: {
|
output: {
|
||||||
filename: "public/app.js"
|
path: path.resolve(__dirname, "dist/public"),
|
||||||
|
filename: "app.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
Reference in new issue
Block a user