|
1 | 1 | const path = require('path'); |
2 | 2 | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); |
3 | | -const TerserPlugin = require('terser-webpack-plugin'); |
4 | 3 |
|
5 | | -module.exports = (env, argv) => { |
6 | | - const isProd = argv.mode === 'production'; |
7 | | - return { |
8 | | - mode: isProd ? 'production' : 'development', // Set to 'production' for minified output |
9 | | - entry: { |
10 | | - "index":'./src/plugins/index.js', |
11 | | - "markdown-text-editor": './src/plugins/markdown/editor.js' |
12 | | - }, |
13 | | - output: { |
14 | | - filename: '[name].min.js', // Output file name |
15 | | - path: path.resolve(__dirname, 'dist'), // Output directory |
16 | | - library: '[name]', // Name of the library |
17 | | - libraryTarget: 'umd', // Universal Module Definition |
18 | | - libraryExport: 'default', // Use default export |
19 | | - globalObject: 'this', // Ensures it works in Node.js and browser |
20 | | - }, |
21 | | - module: { |
22 | | - rules: [ |
23 | | - { |
24 | | - test: /\.css$/, // Handle CSS files |
25 | | - use: [ |
26 | | - |
27 | | - 'style-loader', // Inject CSS into the DOM |
28 | | - 'css-loader', // Translates CSS into CommonJS |
29 | | - 'postcss-loader', // Processes CSS with PostCSS |
30 | | - ], |
31 | | - }, |
32 | | - { |
33 | | - test: /\.m?js$/, // Handle JavaScript files |
34 | | - exclude: /node_modules/, |
35 | | - use: { |
36 | | - loader: 'babel-loader', |
37 | | - options: { |
38 | | - presets: ['@babel/preset-env'], |
39 | | - }, |
| 4 | +module.exports = { |
| 5 | + entry: { |
| 6 | + "index":'./src/plugins/index.js', |
| 7 | + "markdown-text-editor": './src/plugins/markdown/editor.js' |
| 8 | + }, |
| 9 | + output: { |
| 10 | + filename: '[name].js', // Output file name |
| 11 | + path: path.resolve(__dirname, 'dist'), // Output directory |
| 12 | + library: '[name]', // Name of the library |
| 13 | + libraryTarget: 'umd', // Universal Module Definition |
| 14 | + libraryExport: 'default', // Use default export |
| 15 | + globalObject: 'this', // Ensures it works in Node.js and browser |
| 16 | + }, |
| 17 | + module: { |
| 18 | + rules: [ |
| 19 | + { |
| 20 | + test: /\.css$/, // Handle CSS files |
| 21 | + use: [ |
| 22 | + |
| 23 | + 'style-loader', // Inject CSS into the DOM |
| 24 | + 'css-loader', // Translates CSS into CommonJS |
| 25 | + 'postcss-loader', // Processes CSS with PostCSS |
| 26 | + ], |
| 27 | + }, |
| 28 | + { |
| 29 | + test: /\.m?js$/, // Handle JavaScript files |
| 30 | + exclude: /node_modules/, |
| 31 | + use: { |
| 32 | + loader: 'babel-loader', |
| 33 | + options: { |
| 34 | + presets: ['@babel/preset-env'], |
40 | 35 | }, |
41 | 36 | }, |
42 | | - ], |
43 | | - }, |
44 | | - plugins: [ |
45 | | - new MiniCssExtractPlugin({ |
46 | | - filename: '[name].min.css', // Output CSS filename |
47 | | - }), |
| 37 | + }, |
48 | 38 | ], |
49 | | - devtool: isProd ? false : 'source-map', // Enable source maps for easier debugging |
50 | | - optimization: { |
51 | | - minimize: true, // Enable minimization |
52 | | - minimizer: [ |
53 | | - new TerserPlugin({ |
54 | | - terserOptions: { |
55 | | - format: { |
56 | | - comments: false, // Remove comments |
57 | | - }, |
58 | | - }, |
59 | | - }), |
60 | | - ], |
61 | | - } |
62 | | - } |
| 39 | + }, |
| 40 | + plugins: [ |
| 41 | + new MiniCssExtractPlugin({ |
| 42 | + filename: 'styles.css', // Output CSS filename |
| 43 | + }), |
| 44 | + ], |
| 45 | + mode: 'production', // Set to 'production' for minified output |
| 46 | + devtool: 'source-map', // Enable source maps for easier debugging |
63 | 47 | }; |
0 commit comments