From ab59fe732250019a086d8e2087bbb22021d05532 Mon Sep 17 00:00:00 2001 From: Andrew Simachev Date: Fri, 2 Feb 2024 14:29:39 +0100 Subject: [PATCH] rework embed iframe libs --- dist/embed/iframe.html | 82 +++++++++++- extension/lib/index.ts | 77 ----------- src/ts/component/block/embed.tsx | 1 - src/ts/lib/util/embed.ts | 38 ------ webpack.config.js | 220 +++++++++++++------------------ 5 files changed, 175 insertions(+), 243 deletions(-) delete mode 100644 extension/lib/index.ts diff --git a/dist/embed/iframe.html b/dist/embed/iframe.html index 2cd4ba90df..dbe88bf7a3 100644 --- a/dist/embed/iframe.html +++ b/dist/embed/iframe.html @@ -39,6 +39,31 @@ diff --git a/extension/lib/index.ts b/extension/lib/index.ts deleted file mode 100644 index 98fc26d4ad..0000000000 --- a/extension/lib/index.ts +++ /dev/null @@ -1,77 +0,0 @@ -import * as I from 'Interface'; -import * as M from 'Model'; -import Renderer from 'ts/lib/renderer'; - -import * as C from 'ts/lib/api/command'; -import { dispatcher } from 'ts/lib/api/dispatcher'; -import { Mapper } from 'ts/lib/api/mapper'; -import { Encode, Decode } from 'ts/lib/api/struct'; - -import UtilCommon from 'ts/lib/util/common'; -import UtilData from 'ts/lib/util/data'; -import UtilSmile from 'ts/lib/util/smile'; -import UtilFile from 'ts/lib/util/file'; -import UtilObject from 'ts/lib/util/object'; -import UtilMenu from 'ts/lib/util/menu'; -import UtilRouter from 'ts/lib/util/router'; -import UtilDate from 'ts/lib/util/date'; -import UtilGraph from 'ts/lib/util/graph'; -import UtilEmbed from 'ts/lib/util/embed'; - -import { keyboard, Key } from 'ts/lib/keyboard'; -import { sidebar } from 'ts/lib/sidebar'; -import Storage from 'ts/lib/storage'; -import Mark from 'ts/lib/mark'; -import Relation from 'ts/lib/relation'; -import Dataview from 'ts/lib/dataview'; -import { focus } from 'ts/lib/focus'; -import { scrollOnMove } from 'ts/lib/scrollOnMove'; -import { analytics } from 'ts/lib/analytics'; -import { history } from 'ts/lib/history'; -import Action from 'ts/lib/action'; -import Onboarding from 'ts/lib/onboarding'; -import Survey from 'ts/lib/survey'; -import Preview from 'ts/lib/preview'; -import Highlight from 'ts/lib/highlight'; -import Animation from 'ts/lib/animation'; -import { translate } from 'ts/lib/translate'; - -export { - keyboard, - sidebar, - focus, - Key, - Storage, - Mark, - Relation, - Dataview, - I, - C, - M, - translate, - dispatcher, - Mapper, - Encode, - Decode, - analytics, - history, - scrollOnMove, - Action, - Onboarding, - Renderer, - Survey, - Preview, - Highlight, - Animation, - - UtilCommon, - UtilData, - UtilSmile, - UtilFile, - UtilObject, - UtilMenu, - UtilRouter, - UtilDate, - UtilEmbed, - UtilGraph, -}; \ No newline at end of file diff --git a/src/ts/component/block/embed.tsx b/src/ts/component/block/embed.tsx index afd631deb3..8c92a8c73c 100644 --- a/src/ts/component/block/embed.tsx +++ b/src/ts/component/block/embed.tsx @@ -631,7 +631,6 @@ const BlockEmbed = observer(class BlockEmbed extends React.Component`; - libs.push('https://cdn.jsdelivr.net/npm/chart.js'); - break; - }; - - case I.EmbedProcessor.Twitter: { - libs.push('https://platform.twitter.com/widgets.js'); - break; - }; - - case I.EmbedProcessor.Reddit: { - libs.push('https://embed.reddit.com/widgets.js'); - break; - }; - - case I.EmbedProcessor.Instagram: { - libs.push('https://www.instagram.com/embed.js'); - break; - }; - - case I.EmbedProcessor.Codepen: { - libs.push('https://cpwebassets.codepen.io/assets/embed/ei.js'); - break; - }; - }; - - return { - html, - libs, - }; - }; - getLang (processor: I.EmbedProcessor) { switch (processor) { default: return 'html'; diff --git a/webpack.config.js b/webpack.config.js index 0bccf18679..2bf7322377 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,138 +2,108 @@ const path = require('path'); const process = require('process'); const webpack = require('webpack'); const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; -const port = process.env.SERVER_PORT; -const mode = 'development'; -const devtool = 'source-map'; -const optimization = { - minimize: false, - removeAvailableModules: true, - removeEmptyChunks: true, - splitChunks: false, -}; +module.exports = (env, argv) => { + const port = process.env.SERVER_PORT; -const resolve = { - extensions: [ '.ts', '.tsx', '.js', '.jsx' ], - alias: { - dist: path.resolve(__dirname, 'dist'), - json: path.resolve(__dirname, 'src/json'), - Store: path.resolve(__dirname, 'src/ts/store'), - Component: path.resolve(__dirname, 'src/ts/component'), - Interface: path.resolve(__dirname, 'src/ts/interface'), - Model: path.resolve(__dirname, 'src/ts/model'), - Docs: path.resolve(__dirname, 'src/ts/docs'), - }, - modules: [ - path.resolve('./src/'), - path.resolve('./electron/'), - path.resolve('./dist/'), - path.resolve('./node_modules'), - ], -}; + return { + mode: 'development', + devtool: 'source-map', -const devServer = { - hot: true, - static: { - directory: path.join(__dirname, 'dist'), - watch: { - ignored: [ - path.resolve(__dirname, 'dist'), - path.resolve(__dirname, 'node_modules') - ], - usePolling: false, + optimization: { + minimize: false, + removeAvailableModules: true, + removeEmptyChunks: true, + splitChunks: false, }, - }, - historyApiFallback: true, - host: 'localhost', - port, - client: { - progress: false, - }, -}; - -const loaders = { - rules: [ - { - test: /\.ts(x?)$/, - exclude: /node_modules/, - loader: 'ts-loader' - }, - { - enforce: 'pre', - test: /\.js$/, - loader: 'source-map-loader' - }, - { - test: /\.(eot|ttf|otf|woff|woff2)$/, - loader: 'url-loader' - }, - { - test: /\.(jpe?g|png|gif|svg)$/, - loader: 'url-loader' - }, - { - test: /\.s?css/, - use: [ - { loader: 'style-loader' }, - { loader: 'css-loader' }, - { loader: 'sass-loader' } - ] - } - ] -}; - -const plugins = [ - //new BundleAnalyzerPlugin(), - new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }), -]; - -module.exports = [ - - (env, argv) => { - return { - mode, - devtool, - optimization, - devServer, - - entry: './src/ts/entry.tsx', - output: { + + entry: { + app: { + import: './src/ts/entry.tsx', filename: 'main.js', }, - - resolve: Object.assign(resolve, { - alias: Object.assign(resolve.alias, { - Lib: path.resolve(__dirname, 'src/extension/lib'), - }), - }), - - module: loaders, - plugins, - }; - }, - - (env, argv) => { - return { - mode, - devtool, - optimization, - devServer, - - entry: './extension/entry.tsx', - output: { + extension: { + import: './extension/entry.tsx', filename: 'extension/js/main.js', }, + }, - resolve: Object.assign(resolve, { - alias: Object.assign(resolve.alias, { - Lib: path.resolve(__dirname, 'src/ts/lib'), - }), + resolve: { + extensions: [ '.ts', '.tsx', '.js', '.jsx' ], + alias: { + dist: path.resolve(__dirname, 'dist'), + protobuf: path.resolve(__dirname, 'dist/lib'), + json: path.resolve(__dirname, 'src/json'), + Lib: path.resolve(__dirname, 'src/ts/lib'), + Store: path.resolve(__dirname, 'src/ts/store'), + Component: path.resolve(__dirname, 'src/ts/component'), + Interface: path.resolve(__dirname, 'src/ts/interface'), + Model: path.resolve(__dirname, 'src/ts/model'), + Docs: path.resolve(__dirname, 'src/ts/docs'), + }, + modules: [ + path.resolve('./src/'), + path.resolve('./electron/'), + path.resolve('./dist/'), + path.resolve('./node_modules') + ] + }, + + devServer: { + hot: true, + static: { + directory: path.join(__dirname, 'dist'), + watch: { + ignored: [ + path.resolve(__dirname, 'dist'), + path.resolve(__dirname, 'node_modules') + ], + usePolling: false, + }, + }, + historyApiFallback: true, + host: 'localhost', + port, + client: { + progress: false, + }, + }, + + module: { + rules: [ + { + test: /\.ts(x?)$/, + exclude: /node_modules/, + loader: 'ts-loader' + }, + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader' + }, + { + test: /\.(eot|ttf|otf|woff|woff2)$/, + loader: 'url-loader' + }, + { + test: /\.(jpe?g|png|gif|svg)$/, + loader: 'url-loader' + }, + { + test: /\.s?css/, + use: [ + { loader: 'style-loader' }, + { loader: 'css-loader' }, + { loader: 'sass-loader' } + ] + } + ] + }, + plugins: [ + //new BundleAnalyzerPlugin(), + new webpack.optimize.LimitChunkCountPlugin({ + maxChunks: 1, }), - - module: loaders, - plugins, - }; - }, - -]; \ No newline at end of file + ], + }; +}; \ No newline at end of file