mirror of https://github.com/status-im/codimd.git
Refactor webpack module
This commit is contained in:
parent
b90c26fe90
commit
43c9f68b9a
|
@ -2,6 +2,7 @@ var hljs = require('highlight.js');
|
||||||
var PDFObject = require('pdfobject');
|
var PDFObject = require('pdfobject');
|
||||||
var S = require('string');
|
var S = require('string');
|
||||||
var saveAs = require('file-saver').saveAs;
|
var saveAs = require('file-saver').saveAs;
|
||||||
|
require('../vendor/md-toc');
|
||||||
|
|
||||||
//auto update last change
|
//auto update last change
|
||||||
var createtime = null;
|
var createtime = null;
|
||||||
|
@ -262,49 +263,49 @@ function finishView(view) {
|
||||||
MathJax.Hub.Queue(viewAjaxCallback);
|
MathJax.Hub.Queue(viewAjaxCallback);
|
||||||
}
|
}
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
//sequence diagram
|
//sequence diagram
|
||||||
var sequences = view.find(".sequence-diagram.raw").removeClass("raw");
|
var sequences = view.find(".sequence-diagram.raw").removeClass("raw");
|
||||||
sequences.each(function (key, value) {
|
sequences.each(function (key, value) {
|
||||||
try {
|
try {
|
||||||
var $value = $(value);
|
var $value = $(value);
|
||||||
var $ele = $(value).parent().parent();
|
var $ele = $(value).parent().parent();
|
||||||
|
|
||||||
var sequence = $value;
|
var sequence = $value;
|
||||||
sequence.sequenceDiagram({
|
sequence.sequenceDiagram({
|
||||||
theme: 'simple'
|
theme: 'simple'
|
||||||
});
|
});
|
||||||
|
|
||||||
$ele.addClass('sequence-diagram');
|
$ele.addClass('sequence-diagram');
|
||||||
$value.children().unwrap().unwrap();
|
$value.children().unwrap().unwrap();
|
||||||
var svg = $ele.find('> svg');
|
var svg = $ele.find('> svg');
|
||||||
svg[0].setAttribute('viewBox', '0 0 ' + svg.attr('width') + ' ' + svg.attr('height'));
|
svg[0].setAttribute('viewBox', '0 0 ' + svg.attr('width') + ' ' + svg.attr('height'));
|
||||||
svg[0].setAttribute('preserveAspectRatio', 'xMidYMid meet');
|
svg[0].setAttribute('preserveAspectRatio', 'xMidYMid meet');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//flowchart
|
//flowchart
|
||||||
var flow = view.find(".flow-chart.raw").removeClass("raw");
|
var flow = view.find(".flow-chart.raw").removeClass("raw");
|
||||||
flow.each(function (key, value) {
|
flow.each(function (key, value) {
|
||||||
try {
|
try {
|
||||||
var $value = $(value);
|
var $value = $(value);
|
||||||
var $ele = $(value).parent().parent();
|
var $ele = $(value).parent().parent();
|
||||||
|
|
||||||
var chart = flowchart.parse($value.text());
|
var chart = flowchart.parse($value.text());
|
||||||
$value.html('');
|
$value.html('');
|
||||||
chart.drawSVG(value, {
|
chart.drawSVG(value, {
|
||||||
'line-width': 2,
|
'line-width': 2,
|
||||||
'fill': 'none',
|
'fill': 'none',
|
||||||
'font-size': '16px',
|
'font-size': '16px',
|
||||||
'font-family': "'Andale Mono', monospace"
|
'font-family': "'Andale Mono', monospace"
|
||||||
});
|
});
|
||||||
|
|
||||||
$ele.addClass('flow-chart');
|
$ele.addClass('flow-chart');
|
||||||
$value.children().unwrap().unwrap();
|
$value.children().unwrap().unwrap();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//graphviz
|
//graphviz
|
||||||
var Viz = require("viz.js");
|
var Viz = require("viz.js");
|
||||||
var graphvizs = view.find(".graphviz.raw").removeClass("raw");
|
var graphvizs = view.find(".graphviz.raw").removeClass("raw");
|
||||||
|
@ -434,14 +435,14 @@ function finishView(view) {
|
||||||
});
|
});
|
||||||
//pdf
|
//pdf
|
||||||
view.find(".pdf.raw").removeClass("raw")
|
view.find(".pdf.raw").removeClass("raw")
|
||||||
.each(function (key, value) {
|
.each(function (key, value) {
|
||||||
var url = $(value).attr('data-pdfurl');
|
var url = $(value).attr('data-pdfurl');
|
||||||
var inner = $('<div></div>');
|
var inner = $('<div></div>');
|
||||||
$(this).append(inner);
|
$(this).append(inner);
|
||||||
PDFObject.embed(url, inner, {
|
PDFObject.embed(url, inner, {
|
||||||
height: '400px'
|
height: '400px'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
//syntax highlighting
|
//syntax highlighting
|
||||||
view.find("pre.raw").removeClass("raw")
|
view.find("pre.raw").removeClass("raw")
|
||||||
.each(function (key, value) {
|
.each(function (key, value) {
|
||||||
|
|
|
@ -7,25 +7,16 @@ require('bootstrap/dist/css/bootstrap.css');
|
||||||
require('prismjs/themes/prism.css');
|
require('prismjs/themes/prism.css');
|
||||||
require('highlight.js/styles/github-gist.css');
|
require('highlight.js/styles/github-gist.css');
|
||||||
|
|
||||||
/* other vendors plugin */
|
|
||||||
require('gist-embed');
|
|
||||||
require('string');
|
|
||||||
require('prismjs');
|
require('prismjs');
|
||||||
require('prismjs/components/prism-wiki');
|
require('prismjs/components/prism-wiki');
|
||||||
require('to-markdown');
|
var toMarkdown = require('to-markdown');
|
||||||
|
|
||||||
require('raphael');
|
|
||||||
require('js-sequence-diagrams');
|
|
||||||
|
|
||||||
require('flowchart.js');
|
|
||||||
var saveAs = require('file-saver').saveAs;
|
var saveAs = require('file-saver').saveAs;
|
||||||
require('store');
|
|
||||||
require('js-url');
|
require('js-url');
|
||||||
require('visibilityjs');
|
|
||||||
var List = require('list.js');
|
|
||||||
require('../vendor/md-toc');
|
|
||||||
require('randomcolor');
|
require('randomcolor');
|
||||||
|
|
||||||
|
var List = require('list.js');
|
||||||
|
|
||||||
var common = require('./common.js');
|
var common = require('./common.js');
|
||||||
var urlpath = common.urlpath;
|
var urlpath = common.urlpath;
|
||||||
var noteid = common.noteid;
|
var noteid = common.noteid;
|
||||||
|
@ -2268,6 +2259,7 @@ function havePermission() {
|
||||||
window.havePermission = havePermission;
|
window.havePermission = havePermission;
|
||||||
|
|
||||||
//socket.io actions
|
//socket.io actions
|
||||||
|
var io = require("socket.io-client");
|
||||||
var socket = io.connect({
|
var socket = io.connect({
|
||||||
path: urlpath ? '/' + urlpath + '/socket.io/' : '',
|
path: urlpath ? '/' + urlpath + '/socket.io/' : '',
|
||||||
timeout: 5000 //5 secs to timeout
|
timeout: 5000 //5 secs to timeout
|
||||||
|
|
|
@ -15,10 +15,6 @@ require('prismjs');
|
||||||
require('prismjs/components/prism-wiki');
|
require('prismjs/components/prism-wiki');
|
||||||
require('to-markdown');
|
require('to-markdown');
|
||||||
|
|
||||||
require('raphael');
|
|
||||||
require('js-sequence-diagrams');
|
|
||||||
|
|
||||||
require('flowchart.js');
|
|
||||||
require('file-saver');
|
require('file-saver');
|
||||||
require('store');
|
require('store');
|
||||||
require('js-url');
|
require('js-url');
|
||||||
|
|
|
@ -4,19 +4,11 @@ require('bootstrap/dist/css/bootstrap.css');
|
||||||
require('prismjs/themes/prism.css');
|
require('prismjs/themes/prism.css');
|
||||||
|
|
||||||
/* other vendors plugin */
|
/* other vendors plugin */
|
||||||
require('gist-embed');
|
|
||||||
var S = require('string');
|
var S = require('string');
|
||||||
require('prismjs');
|
require('prismjs');
|
||||||
require('prismjs/components/prism-wiki');
|
require('prismjs/components/prism-wiki');
|
||||||
require('to-markdown');
|
require('to-markdown');
|
||||||
|
|
||||||
require('raphael');
|
|
||||||
require('js-sequence-diagrams');
|
|
||||||
|
|
||||||
require('flowchart.js');
|
|
||||||
require('file-saver');
|
|
||||||
require('store');
|
|
||||||
require('visibilityjs');
|
|
||||||
require('../vendor/md-toc');
|
require('../vendor/md-toc');
|
||||||
require('randomcolor');
|
require('randomcolor');
|
||||||
|
|
||||||
|
|
|
@ -11,12 +11,12 @@ module.exports = Object.assign({}, baseConfig, {
|
||||||
Visibility: "visibilityjs",
|
Visibility: "visibilityjs",
|
||||||
Cookies: "js-cookie",
|
Cookies: "js-cookie",
|
||||||
emojify: "emojify.js",
|
emojify: "emojify.js",
|
||||||
io: "socket.io-client",
|
|
||||||
key: "keymaster"
|
key: "keymaster"
|
||||||
}),
|
}),
|
||||||
new ExtractTextPlugin("[name].css"),
|
new ExtractTextPlugin("[name].css"),
|
||||||
new webpack.optimize.CommonsChunkPlugin({
|
new webpack.optimize.CommonsChunkPlugin({
|
||||||
name: ["vendor", "public", "slide", "locale"],
|
names: ["vendor", "public", "slide", "locale"],
|
||||||
|
children: true,
|
||||||
async: true,
|
async: true,
|
||||||
filename: '[name].js',
|
filename: '[name].js',
|
||||||
minChunks: Infinity
|
minChunks: Infinity
|
||||||
|
@ -78,6 +78,7 @@ module.exports = Object.assign({}, baseConfig, {
|
||||||
compress: {
|
compress: {
|
||||||
warnings: false
|
warnings: false
|
||||||
},
|
},
|
||||||
|
mangle: false,
|
||||||
sourceMap: false
|
sourceMap: false
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
var webpack = require('webpack');
|
var webpack = require('webpack');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var ExtractTextPlugin = require("extract-text-webpack-plugin");
|
var ExtractTextPlugin = require("extract-text-webpack-plugin");
|
||||||
|
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
plugins: [
|
plugins: [
|
||||||
|
@ -9,15 +10,63 @@ module.exports = {
|
||||||
Visibility: "visibilityjs",
|
Visibility: "visibilityjs",
|
||||||
Cookies: "js-cookie",
|
Cookies: "js-cookie",
|
||||||
emojify: "emojify.js",
|
emojify: "emojify.js",
|
||||||
io: "socket.io-client",
|
|
||||||
key: "keymaster"
|
key: "keymaster"
|
||||||
}),
|
}),
|
||||||
new ExtractTextPlugin("[name].css"),
|
new ExtractTextPlugin("[name].css"),
|
||||||
new webpack.optimize.CommonsChunkPlugin({
|
new webpack.optimize.CommonsChunkPlugin({
|
||||||
name: ["vendor", "public", "slide", "locale"],
|
names: ["vendor", "public", "slide", "locale"],
|
||||||
|
children: true,
|
||||||
async: true,
|
async: true,
|
||||||
filename: '[name].js',
|
filename: '[name].js',
|
||||||
minChunks: Infinity
|
minChunks: Infinity
|
||||||
|
}),
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: 'public/views/includes/header.ejs',
|
||||||
|
chunks: ['vendor', 'index'],
|
||||||
|
filename: path.join(__dirname, 'public/views/build/index-header.ejs'),
|
||||||
|
inject: false
|
||||||
|
}),
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: 'public/views/includes/scripts.ejs',
|
||||||
|
chunks: ['vendor', 'index'],
|
||||||
|
filename: path.join(__dirname, 'public/views/build/index-scripts.ejs'),
|
||||||
|
inject: false
|
||||||
|
}),
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: 'public/views/includes/header.ejs',
|
||||||
|
chunks: ['vendor', 'locale'],
|
||||||
|
filename: path.join(__dirname, 'public/views/build/cover-header.ejs'),
|
||||||
|
inject: false
|
||||||
|
}),
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: 'public/views/includes/scripts.ejs',
|
||||||
|
chunks: ['vendor', 'locale'],
|
||||||
|
filename: path.join(__dirname, 'public/views/build/cover-scripts.ejs'),
|
||||||
|
inject: false
|
||||||
|
}),
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: 'public/views/includes/header.ejs',
|
||||||
|
chunks: ['vendor', 'public'],
|
||||||
|
filename: path.join(__dirname, 'public/views/build/pretty-header.ejs'),
|
||||||
|
inject: false
|
||||||
|
}),
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: 'public/views/includes/scripts.ejs',
|
||||||
|
chunks: ['vendor', 'public'],
|
||||||
|
filename: path.join(__dirname, 'public/views/build/pretty-scripts.ejs'),
|
||||||
|
inject: false
|
||||||
|
}),
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: 'public/views/includes/header.ejs',
|
||||||
|
chunks: ['vendor', 'slide'],
|
||||||
|
filename: path.join(__dirname, 'public/views/build/slide-header.ejs'),
|
||||||
|
inject: false
|
||||||
|
}),
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: 'public/views/includes/scripts.ejs',
|
||||||
|
chunks: ['vendor', 'slide'],
|
||||||
|
filename: path.join(__dirname, 'public/views/build/slide-scripts.ejs'),
|
||||||
|
inject: false
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|
||||||
|
@ -34,21 +83,23 @@ module.exports = {
|
||||||
"jquery-ui/ui/widgets/tooltip",
|
"jquery-ui/ui/widgets/tooltip",
|
||||||
"jquery-ui/ui/widgets/controlgroup",
|
"jquery-ui/ui/widgets/controlgroup",
|
||||||
"jquery-ui/ui/widgets/autocomplete",
|
"jquery-ui/ui/widgets/autocomplete",
|
||||||
"expose?LZString!lz-string",
|
"script!gist-embed",
|
||||||
"expose?filterXSS!xss",
|
"expose?filterXSS!xss",
|
||||||
"js-url",
|
"js-url",
|
||||||
"bootstrap",
|
"bootstrap",
|
||||||
"expose?Spinner!spin.js",
|
"expose?Spinner!spin.js",
|
||||||
"script!Idle.Js",
|
"script!Idle.Js",
|
||||||
"expose?Viz!viz.js",
|
"expose?LZString!lz-string",
|
||||||
"expose?ListPagination!list.pagination.js/dist/list.pagination.js",
|
"expose?ListPagination!list.pagination.js/dist/list.pagination.js",
|
||||||
path.join(__dirname, 'public/vendor/codemirror/codemirror.min.js'),
|
"script!codemirror",
|
||||||
path.join(__dirname, 'public/vendor/select2/select2.min.js'),
|
"script!select2",
|
||||||
path.join(__dirname, 'public/vendor/inlineAttachment/inline-attachment.js'),
|
"script!inlineAttachment",
|
||||||
path.join(__dirname, 'public/vendor/jquery-textcomplete/jquery.textcomplete.js'),
|
"script!jqueryTextcomplete",
|
||||||
path.join(__dirname, 'public/vendor/codemirror-spell-checker/spell-checker.min.js'),
|
"script!codemirrorSpellChecker",
|
||||||
path.join(__dirname, 'public/vendor/inlineAttachment/codemirror.inline-attachment.js'),
|
"script!codemirrorInlineAttachment",
|
||||||
path.join(__dirname, 'public/vendor/ot/ot.min.js')
|
"script!ot",
|
||||||
|
"flowchart.js",
|
||||||
|
"js-sequence-diagrams"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -59,11 +110,20 @@ module.exports = {
|
||||||
},
|
},
|
||||||
|
|
||||||
resolve: {
|
resolve: {
|
||||||
root: [
|
modulesDirectories: [
|
||||||
path.resolve(__dirname, 'src'),
|
path.resolve(__dirname, 'src'),
|
||||||
path.resolve(__dirname, 'node_modules')
|
path.resolve(__dirname, 'node_modules')
|
||||||
],
|
],
|
||||||
extensions: ["", ".js"]
|
extensions: ["", ".js"],
|
||||||
|
alias: {
|
||||||
|
codemirror: path.join(__dirname, 'public/vendor/codemirror/codemirror.min.js'),
|
||||||
|
select2: path.join(__dirname, 'public/vendor/select2/select2.min.js'),
|
||||||
|
inlineAttachment: path.join(__dirname, 'public/vendor/inlineAttachment/inline-attachment.js'),
|
||||||
|
jqueryTextcomplete: path.join(__dirname, 'public/vendor/jquery-textcomplete/jquery.textcomplete.js'),
|
||||||
|
codemirrorSpellChecker: path.join(__dirname, 'public/vendor/codemirror-spell-checker/spell-checker.min.js'),
|
||||||
|
codemirrorInlineAttachment: path.join(__dirname, 'public/vendor/inlineAttachment/codemirror.inline-attachment.js'),
|
||||||
|
ot: path.join(__dirname, 'public/vendor/ot/ot.min.js')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
externals: {
|
externals: {
|
||||||
|
@ -98,19 +158,11 @@ module.exports = {
|
||||||
}, {
|
}, {
|
||||||
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
|
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
|
||||||
loader: "url?limit=10000&mimetype=image/svg+xml"
|
loader: "url?limit=10000&mimetype=image/svg+xml"
|
||||||
}, {
|
}],
|
||||||
test: /\.js/,
|
|
||||||
loader: "script-loader",
|
noParse: [
|
||||||
include: [
|
"gist-embed"
|
||||||
path.join(__dirname, 'public/vendor/codemirror/codemirror.min.js'),
|
]
|
||||||
path.join(__dirname, 'public/vendor/inlineAttachment/inline-attachment.js'),
|
|
||||||
path.join(__dirname, 'public/vendor/jquery-textcomplete/jquery.textcomplete.js'),
|
|
||||||
path.join(__dirname, 'public/vendor/select2/select2.min.js'),
|
|
||||||
path.join(__dirname, 'public/vendor/inlineAttachment/codemirror.inline-attachment.js'),
|
|
||||||
path.join(__dirname, 'public/vendor/codemirror-spell-checker/spell-checker.min.js'),
|
|
||||||
path.join(__dirname, 'public/vendor/ot/ot.min.js')
|
|
||||||
]
|
|
||||||
}]
|
|
||||||
},
|
},
|
||||||
|
|
||||||
node: {
|
node: {
|
||||||
|
|
Loading…
Reference in New Issue