Browse Source

:art: https://github.com/Vanessa219/vditor/issues/1653

Vanessa 1 year ago
parent
commit
365d2541a1
2 changed files with 122 additions and 120 deletions
  1. 1 1
      package.json
  2. 121 119
      webpack.config.js

+ 1 - 1
package.json

@@ -5,7 +5,7 @@
   "author": "Vanessa <[email protected]> (http://vanessa.b3log.org)",
   "homepage": "https://b3log.org/vditor",
   "jsdelivr": "dist/index.min.js",
-  "main": "dist/index.min.js",
+  "main": "dist/index.js",
   "funding": "https://ld246.com/sponsor",
   "files": [
     "dist/*",

+ 121 - 119
webpack.config.js

@@ -12,10 +12,10 @@ 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
+    'webpack-bundle-analyzer').BundleAnalyzerPlugin
 const pkg = require('./package.json')
 const banner = new webpack.BannerPlugin({
-  banner: `Vditor v${pkg.version} - A markdown editor written in TypeScript.
+    banner: `Vditor v${pkg.version} - A markdown editor written in TypeScript.
 
 MIT License
 
@@ -39,130 +39,132 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 `,
-  entryOnly: true,
+    entryOnly: true,
 })
 
 module.exports = [
-  {
-    mode: 'production',
-    output: {
-      filename: '[name].js',
-      path: path.resolve(__dirname, 'dist'),
-      // chunkFilename: '[name].bundle.js',
-      // publicPath: `${pkg.cdn}/vditor@${pkg.version}/dist/`,
-      libraryTarget: 'umd',
-      library: 'Vditor',
-      libraryExport: 'default',
-      globalObject: 'this',
-    },
-    entry: {
-      'index.min': './src/index.ts',
-      'method.min': './src/method.ts',
-    },
-    optimization: {
-      minimize: true,
-      minimizer: [
-        new TerserPlugin({
-          include: ['index.min.js', 'method.min.js'],
-          terserOptions: {
-            format: {
-              comments: false,
-            },
-          },
-          extractComments: false,
-        }),
-      ],
-    },
-    resolve: {
-      extensions: ['.ts', '.js', '.less', 'png'],
-    },
-    module: {
-      rules: [
-        {
-          test: /\.png$/,
-          include: [path.resolve(__dirname, './src/assets/images')],
-          use: [
-            'file-loader',
-          ],
+    {
+        mode: 'production',
+        output: {
+            filename: '[name].js',
+            path: path.resolve(__dirname, 'dist'),
+            // chunkFilename: '[name].bundle.js',
+            // publicPath: `${pkg.cdn}/vditor@${pkg.version}/dist/`,
+            libraryTarget: 'umd',
+            library: 'Vditor',
+            libraryExport: 'default',
+            globalObject: 'this',
         },
-        {
-          test: /\.js$/,
-          exclude: '/node_modules/',
-          use: {
-            loader: 'babel-loader',
-            options: {
-              presets: [
-                [
-                  '@babel/env',
-                  {
-                    targets: {
-                      browsers: [
-                        'last 2 Chrome major versions',
-                        'last 2 Firefox major versions',
-                        'last 2 Safari major versions',
-                        'last 2 Edge major versions',
-                        'last 2 iOS major versions',
-                        'last 2 ChromeAndroid major versions',
-                      ],
+        entry: {
+            'index.min': './src/index.ts',
+            'method.min': './src/method.ts',
+            'index': './src/index.ts',
+            'method': './src/method.ts',
+        },
+        optimization: {
+            minimize: true,
+            minimizer: [
+                new TerserPlugin({
+                    include: ['index.min.js', 'method.min.js'],
+                    terserOptions: {
+                        format: {
+                            comments: false,
+                        },
                     },
-                  },
-                ],
-              ],
-            },
-          },
+                    extractComments: false,
+                }),
+            ],
         },
-        {
-          test: /\.ts$/,
-          use: 'ts-loader',
+        resolve: {
+            extensions: ['.ts', '.js', '.less', 'png'],
         },
-        {
-          test: /\.less$/,
-          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}],
-                  ],
+        module: {
+            rules: [
+                {
+                    test: /\.png$/,
+                    include: [path.resolve(__dirname, './src/assets/images')],
+                    use: [
+                        'file-loader',
+                    ],
+                },
+                {
+                    test: /\.js$/,
+                    exclude: '/node_modules/',
+                    use: {
+                        loader: 'babel-loader',
+                        options: {
+                            presets: [
+                                [
+                                    '@babel/env',
+                                    {
+                                        targets: {
+                                            browsers: [
+                                                'last 2 Chrome major versions',
+                                                'last 2 Firefox major versions',
+                                                'last 2 Safari major versions',
+                                                'last 2 Edge major versions',
+                                                'last 2 iOS major versions',
+                                                'last 2 ChromeAndroid major versions',
+                                            ],
+                                        },
+                                    },
+                                ],
+                            ],
+                        },
+                    },
                 },
-              },
-            },
-            {
-              loader: 'less-loader', // compiles Less to CSS
-            },
-          ],
+                {
+                    test: /\.ts$/,
+                    use: 'ts-loader',
+                },
+                {
+                    test: /\.less$/,
+                    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: 'less-loader', // compiles Less 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'},
-          {from: 'types', to: 'types'},
+        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'},
+                    {from: 'types', to: 'types'},
+                ],
+            }),
         ],
-      }),
-    ],
-  }]
+    }]