Browse Source

:arrow_up:

Vanessa 4 years ago
parent
commit
2e2da15e61
7 changed files with 1043 additions and 259 deletions
  1. 947 125
      package-lock.json
  2. 21 22
      package.json
  3. 4 3
      src/index.ts
  4. 5 5
      src/ts/undo/index.ts
  5. 3 8
      tsconfig.json
  6. 58 82
      webpack.config.js
  7. 5 14
      webpack.start.js

File diff suppressed because it is too large
+ 947 - 125
package-lock.json


+ 21 - 22
package.json

@@ -19,36 +19,35 @@
   },
   "types": "dist/index.d.ts",
   "devDependencies": {
-    "@babel/core": "^7.10.4",
-    "@babel/preset-env": "^7.10.4",
+    "@babel/core": "^7.14.2",
+    "@babel/preset-env": "^7.14.2",
     "@types/diff-match-patch": "^1.0.32",
-    "@types/jest": "^26.0.19",
-    "@types/puppeteer": "^2.1.1",
-    "autoprefixer": "^9.8.4",
-    "babel-loader": "^8.1.0",
-    "copy-webpack-plugin": "^6.0.3",
-    "css-loader": "^3.6.0",
+    "@types/jest": "^26.0.23",
+    "@types/puppeteer": "^2.1.5",
+    "autoprefixer": "^9.8.6",
+    "babel-loader": "^8.2.2",
+    "clean-webpack-plugin": "^4.0.0-alpha.0",
+    "copy-webpack-plugin": "^6.4.1",
+    "css-loader": "^5.2.4",
     "file-loader": "^4.3.0",
-    "html-webpack-plugin": "^3.2.0",
+    "html-webpack-plugin": "^5.3.1",
     "identity-obj-proxy": "^3.0.0",
     "jest": "^26.6.3",
     "mini-css-extract-plugin": "^0.8.2",
     "node-sass": "^4.14.1",
-    "on-build-webpack": "^0.1.0",
-    "optimize-css-assets-webpack-plugin": "^5.0.3",
-    "postcss-loader": "^3.0.0",
+    "postcss-loader": "^5.2.0",
     "puppeteer": "^1.20.0",
-    "rimraf": "^3.0.2",
-    "sass-loader": "^7.3.1",
-    "style-loader": "^1.2.1",
-    "ts-jest": "^26.4.4",
+    "sass-loader": "^10.2.0",
+    "style-loader": "^1.3.0",
+    "terser-webpack-plugin": "^5.1.2",
+    "ts-jest": "^26.5.6",
     "ts-loader": "^6.2.2",
     "tslint": "^5.20.1",
-    "typescript": "^3.9.6",
-    "webpack": "^4.43.0",
-    "webpack-bundle-analyzer": "^3.8.0",
-    "webpack-cli": "^3.3.12",
-    "webpack-dev-server": "^3.11.0"
+    "typescript": "^3.9.9",
+    "webpack": "^5.37.0",
+    "webpack-bundle-analyzer": "^3.9.0",
+    "webpack-cli": "^4.7.0",
+    "webpack-dev-server": "^3.11.2"
   },
   "license": "MIT",
   "repository": "git://github.com/Vanessa219/vditor.git",
@@ -59,7 +58,7 @@
     "lint": "tslint --fix -c tslint.json '{src,types}/**/*.ts'",
     "test:watch": "jest --watch",
     "test": "jest --coverage",
-    "start": "webpack-dev-server --config webpack.start.js",
+    "start": "webpack serve --config webpack.start.js",
     "build": "webpack"
   },
   "keywords": [

+ 4 - 3
src/index.ts

@@ -1,9 +1,10 @@
+import "./assets/scss/index.scss";
 import VditorMethod from "./method";
 import {Constants, VDITOR_VERSION} from "./ts/constants";
-import {DevTools} from "./ts/devtools";
+import {DevTools} from "./ts/devtools/index";
 import {Hint} from "./ts/hint/index";
-import {i18n} from "./ts/i18n";
-import {IR} from "./ts/ir";
+import {i18n} from "./ts/i18n/index";
+import {IR} from "./ts/ir/index";
 import {input as irInput} from "./ts/ir/input";
 import {processAfterRender} from "./ts/ir/process";
 import {getHTML} from "./ts/markdown/getHTML";

+ 5 - 5
src/ts/undo/index.ts

@@ -1,4 +1,4 @@
-import DiffMatchPatch, {diff_match_patch, patch_obj} from "diff-match-patch";
+import * as DiffMatchPatch from "diff-match-patch";
 import {disableToolbar, enableToolbar, hidePanel} from "../toolbar/setToolbar";
 import {isFirefox, isSafari} from "../util/compatibility";
 import {scrollCenter} from "../util/editorCommonEvent";
@@ -10,13 +10,13 @@ import {setRangeByWbr, setSelectionFocus} from "../util/selection";
 interface IUndo {
     hasUndo: boolean;
     lastText: string;
-    redoStack: patch_obj[][];
-    undoStack: patch_obj[][];
+    redoStack: DiffMatchPatch.patch_obj[][];
+    undoStack: DiffMatchPatch.patch_obj[][];
 }
 
 class Undo {
     private stackSize = 50;
-    private dmp: diff_match_patch;
+    private dmp: DiffMatchPatch.diff_match_patch;
     private wysiwyg: IUndo;
     private ir: IUndo;
     private sv: IUndo;
@@ -131,7 +131,7 @@ class Undo {
         }
     }
 
-    private renderDiff(state: patch_obj[], vditor: IVditor, isRedo: boolean = false) {
+    private renderDiff(state: DiffMatchPatch.patch_obj[], vditor: IVditor, isRedo: boolean = false) {
         let text;
         if (isRedo) {
             const redoPatchList = this.dmp.patch_deepCopy(state).reverse();

+ 3 - 8
tsconfig.json

@@ -4,27 +4,22 @@
     "noImplicitAny": true,
     "module": "esnext",
     "target": "es5",
-    "noUnusedLocals": true,
     "lib": [
       "dom",
       "ESNext"
     ],
-    "moduleResolution": "node",
-    "esModuleInterop": true,
     "typeRoots": [
       "./node_modules/@types"
     ],
     "types": [
-      "./types",
-      "node",
-      "jest"
+      "./types"
     ],
-    "declaration": true
+    "declaration": true,
   },
   "include": [
     "src"
   ],
   "exclude": [
-    "node_modules"
+    "node_modules",
   ]
 }

+ 58 - 82
webpack.config.js

@@ -6,12 +6,11 @@
  */
 
 const path = require('path')
-const fs = require('fs')
 const webpack = require('webpack')
 const MiniCssExtractPlugin = require('mini-css-extract-plugin')
-const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
-const WebpackOnBuildPlugin = require('on-build-webpack')
+const {CleanWebpackPlugin} = require('clean-webpack-plugin')
 const CopyPlugin = require('copy-webpack-plugin')
+const TerserPlugin = require('terser-webpack-plugin')
 const BundleAnalyzerPlugin = require(
   'webpack-bundle-analyzer').BundleAnalyzerPlugin
 const pkg = require('./package.json')
@@ -43,73 +42,8 @@ SOFTWARE.
   entryOnly: true,
 })
 
-const rimraf = require('rimraf')
-
-rimraf.sync('./dist', {}, () => {
-  console.log('rm dist')
-})
-
 module.exports = [
   {
-    mode: 'production',
-    entry: {
-      'index': './src/assets/scss/index.scss',
-    },
-    resolve: {
-      extensions: ['.scss'],
-    },
-    module: {
-      rules: [
-        {
-          test: /\.scss$/,
-          include: [path.resolve(__dirname, 'src/assets')],
-          use: [
-            MiniCssExtractPlugin.loader,
-            {
-              loader: 'css-loader', // translates CSS into CommonJS
-              options: {
-                url: false,
-              },
-            },
-            {
-              loader: 'postcss-loader',
-              options: {
-                ident: 'postcss',
-                plugins: () => [
-                  require('autoprefixer')({grid: true, remove: false}),
-                ],
-              },
-            },
-            {
-              loader: 'sass-loader', // compiles Sass to CSS
-            },
-          ],
-        },
-      ],
-    },
-    optimization: {
-      minimizer: [
-        new OptimizeCSSAssetsPlugin({}),
-      ],
-    },
-    plugins: [
-      banner,
-      new MiniCssExtractPlugin({
-        filename: '[name].css',
-      }),
-      new WebpackOnBuildPlugin(() => {
-        fs.unlinkSync('./dist/index.js')
-      }),
-      new CopyPlugin({
-        patterns: [
-          {from: 'src/css', to: 'css'},
-          {from: 'src/images', to: 'images'},
-          {from: 'src/js', to: 'js'},
-          {from: 'types', to: 'types'},
-        ],
-      }),
-    ],
-  }, {
     mode: 'production',
     output: {
       filename: '[name].js',
@@ -119,14 +53,14 @@ module.exports = [
       libraryTarget: 'umd',
       library: 'Vditor',
       libraryExport: 'default',
-	  globalObject: 'this',
+      globalObject: 'this',
     },
     entry: {
       'index.min': './src/index.ts',
       'method.min': './src/method.ts',
     },
     resolve: {
-      extensions: ['.js', '.ts', 'png'],
+      extensions: ['.ts', '.js', '.scss', 'png'],
     },
     module: {
       rules: [
@@ -167,25 +101,67 @@ module.exports = [
           test: /\.ts$/,
           use: 'ts-loader',
         },
+        {
+          test: /\.scss$/,
+          include: [path.resolve(__dirname, 'src/assets')],
+          use: [
+            MiniCssExtractPlugin.loader,
+            {
+              loader: 'css-loader', // translates CSS into CommonJS
+              options: {
+                url: false,
+              },
+            },
+            {
+              loader: 'postcss-loader',
+              options: {
+                postcssOptions: {
+                  plugins: [
+                    ['autoprefixer', {grid: true, remove: false}],
+                  ],
+                },
+              },
+            },
+            {
+              loader: 'sass-loader', // compiles Sass to CSS
+            },
+          ],
+        },
       ],
     },
     plugins: [
       // new BundleAnalyzerPlugin(),
+      new CleanWebpackPlugin({
+        cleanOnceBeforeBuildPatterns: [
+          path.join(__dirname, 'dist')],
+      }),
       new webpack.DefinePlugin({
         VDITOR_VERSION: JSON.stringify(pkg.version),
       }),
+      new MiniCssExtractPlugin({
+        filename: 'index.css',
+      }),
       banner,
+      new CopyPlugin({
+        patterns: [
+          {from: 'src/css', to: 'css'},
+          {from: 'src/images', to: 'images'},
+          {from: 'src/js', to: 'js'},
+        ],
+      }),
     ],
-    // optimization: {
-    //   namedModules: true,
-    //   namedChunks: true,
-    //   splitChunks: {
-    //     cacheGroups: {
-    //       default: false,
-    //       vendors: {
-    //         test: /null/,
-    //       },
-    //     },
-    //   },
-    // },
+    optimization: {
+      minimize: true,
+      minimizer: [
+        new TerserPlugin({
+          include: /\/src\/ts/,
+          terserOptions: {
+            format: {
+              comments: false,
+            },
+          },
+          extractComments: false,
+        }),
+      ],
+    },
   }]

+ 5 - 14
webpack.start.js

@@ -14,7 +14,6 @@ const pkg = require('./package.json')
 
 module.exports = {
   mode: 'development',
-  watch: true,
   output: {
     filename: '[name]',
     path: path.resolve(__dirname, 'demo/dist'),
@@ -46,10 +45,11 @@ module.exports = {
           {
             loader: 'postcss-loader',
             options: {
-              ident: 'postcss',
-              plugins: () => [
-                require('autoprefixer')({grid: true, remove: false}),
-              ],
+              postcssOptions: {
+                plugins: [
+                  ['autoprefixer', {grid: true, remove: false}],
+                ],
+              },
             },
           },
           {
@@ -133,15 +133,6 @@ module.exports = {
     contentBase: path.join(__dirname, '.'),
     port: 9000,
     host: '0.0.0.0',
-    before: (app) => {
-      app.get('/dist/js/lute/lute.wasm.br', function (req, res, next) {
-        res.set({
-          'Content-Encoding': 'br',
-          'Content-Type': 'application/wasm',
-        })
-        next()
-      })
-    },
     proxy: {
       '/api': {
         target: 'http://localhost:8080',

Some files were not shown because too many files changed in this diff