secure-custom-fields
Last commit date
assets
1 year ago
includes
1 year ago
lang
1 year ago
pro
1 year ago
README.md
1 year ago
acf.php
1 year ago
index.php
1 year ago
license.txt
1 year ago
package-lock.json
1 year ago
package.json
1 year ago
readme.txt
1 year ago
webpack.config.js
1 year ago
webpack.config.js
112 lines
| 1 | const path = require('path'); |
| 2 | const TerserPlugin = require('terser-webpack-plugin'); |
| 3 | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); |
| 4 | const CssMinimizerPlugin = require('css-minimizer-webpack-plugin'); |
| 5 | const FixStyleOnlyEntriesPlugin = require("webpack-fix-style-only-entries"); |
| 6 | |
| 7 | // Common configuration for both builds |
| 8 | const commonConfig = { |
| 9 | entry: { |
| 10 | // JavaScript files |
| 11 | 'js/acf-escaped-html-notice': './assets/src/js/acf-escaped-html-notice.js', |
| 12 | 'js/acf-field-group': './assets/src/js/acf-field-group.js', |
| 13 | 'js/acf-input': './assets/src/js/acf-input.js', |
| 14 | 'js/acf-internal-post-type': './assets/src/js/acf-internal-post-type.js', |
| 15 | 'js/acf': './assets/src/js/acf.js', |
| 16 | 'js/pro/acf-pro-blocks': './assets/src/js/pro/acf-pro-blocks.js', |
| 17 | 'js/pro/acf-pro-field-group': './assets/src/js/pro/acf-pro-field-group.js', |
| 18 | 'js/pro/acf-pro-input': './assets/src/js/pro/acf-pro-input.js', |
| 19 | 'js/pro/acf-pro-ui-options-page': './assets/src/js/pro/acf-pro-ui-options-page.js', |
| 20 | |
| 21 | // CSS files |
| 22 | 'css/acf-dark': './assets/src/sass/acf-dark.scss', |
| 23 | 'css/acf-field-group': './assets/src/sass/acf-field-group.scss', |
| 24 | 'css/acf-global': './assets/src/sass/acf-global.scss', |
| 25 | 'css/acf-input': './assets/src/sass/acf-input.scss', |
| 26 | 'css/pro/acf-pro-field-group': './assets/src/sass/pro/acf-pro-field-group.scss', |
| 27 | 'css/pro/acf-pro-input': './assets/src/sass/pro/acf-pro-input.scss', |
| 28 | }, |
| 29 | output: { |
| 30 | path: path.resolve(__dirname, 'assets/build/'), |
| 31 | }, |
| 32 | module: { |
| 33 | rules: [ |
| 34 | { |
| 35 | test: /\.(js|jsx)$/, |
| 36 | exclude: /node_modules/, |
| 37 | use: { |
| 38 | loader: 'babel-loader', |
| 39 | options: { |
| 40 | presets: ['@babel/preset-react'] |
| 41 | } |
| 42 | }, |
| 43 | }, |
| 44 | { |
| 45 | test: /\.scss$/, |
| 46 | use: [ |
| 47 | MiniCssExtractPlugin.loader, // Extract CSS into separate files. |
| 48 | { |
| 49 | loader: 'css-loader', |
| 50 | options: { |
| 51 | url: false, // Don't resolve URLs. |
| 52 | }, |
| 53 | }, |
| 54 | 'sass-loader', |
| 55 | ], |
| 56 | } |
| 57 | ], |
| 58 | }, |
| 59 | }; |
| 60 | |
| 61 | // Unminified build |
| 62 | const unminifiedConfig = { |
| 63 | ...commonConfig, |
| 64 | mode: 'development', |
| 65 | output: { |
| 66 | ...commonConfig.output, |
| 67 | filename: '[name].js', // Unminified output |
| 68 | }, |
| 69 | devtool: 'source-map', |
| 70 | optimization: { |
| 71 | minimize: false, // No minification for this config |
| 72 | }, |
| 73 | plugins: [ |
| 74 | new FixStyleOnlyEntriesPlugin(), |
| 75 | new MiniCssExtractPlugin({ |
| 76 | filename: '[name].css', // Output CSS as .css |
| 77 | }), |
| 78 | ], |
| 79 | }; |
| 80 | |
| 81 | // Minified build |
| 82 | const minifiedConfig = { |
| 83 | ...commonConfig, |
| 84 | mode: 'production', |
| 85 | output: { |
| 86 | ...commonConfig.output, |
| 87 | filename: '[name].min.js', // Minified output |
| 88 | }, |
| 89 | optimization: { |
| 90 | minimize: true, // Enable minification |
| 91 | minimizer: [ |
| 92 | new TerserPlugin({ |
| 93 | terserOptions: { |
| 94 | format: { |
| 95 | comments: false, // Remove comments |
| 96 | }, |
| 97 | }, |
| 98 | extractComments: false, |
| 99 | }), |
| 100 | new CssMinimizerPlugin(), // Minify CSS |
| 101 | ], |
| 102 | }, |
| 103 | plugins: [ |
| 104 | new FixStyleOnlyEntriesPlugin(), |
| 105 | new MiniCssExtractPlugin({ |
| 106 | filename: '[name].min.css', // Changed to output .min.css files |
| 107 | }), |
| 108 | ], |
| 109 | }; |
| 110 | |
| 111 | // Export both configurations |
| 112 | module.exports = [unminifiedConfig, minifiedConfig]; |