|
1 | 1 | const path = require('path') |
2 | 2 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin') |
| 3 | +const webpack = require('webpack') |
3 | 4 |
|
4 | 5 | module.exports = { |
5 | 6 | mode: 'production', |
6 | | - entry: { |
7 | | - "mjml": ['../mjml/lib/index'], |
8 | | - }, |
9 | | - optimization: { |
10 | | - minimizer: [ |
11 | | - new UglifyJsPlugin({ |
12 | | - uglifyOptions: { |
13 | | - ecma: 5, |
14 | | - keep_classnames: true, |
15 | | - keep_fnames: true, |
16 | | - compress: { |
17 | | - passes: 2, |
18 | | - keep_fargs: false, |
19 | | - }, |
20 | | - output: { |
21 | | - beautify: false, |
22 | | - }, |
23 | | - mangle: true, |
24 | | - }, |
25 | | - }), |
26 | | - ], |
27 | | - }, |
| 7 | + entry: path.resolve(__dirname, '../mjml/lib/index'), |
28 | 8 | output: { |
29 | | - library: 'mjml', |
| 9 | + path: __dirname, |
30 | 10 | filename: 'index.js', |
31 | | - path: path.resolve(__dirname, './lib'), |
| 11 | + library: 'mjml', |
32 | 12 | libraryTarget: 'umd', |
33 | 13 | umdNamedDefine: true, |
| 14 | + globalObject: 'typeof self !== "undefined" ? self : this', |
| 15 | + }, |
| 16 | + performance: { |
| 17 | + hints: false, |
34 | 18 | }, |
35 | 19 | resolve: { |
36 | 20 | alias: { |
37 | | - 'path': path.resolve(__dirname, 'browser-mocks/path'), |
38 | | - 'fs': path.resolve(__dirname, 'browser-mocks/fs'), |
39 | | - 'uglify-js': path.resolve(__dirname, 'browser-mocks/uglify-js'), |
| 21 | + // Existing aliases |
| 22 | + stream: require.resolve('stream-browserify'), |
| 23 | + 'node:stream': require.resolve('stream-browserify'), |
| 24 | + buffer: require.resolve('buffer/'), |
| 25 | + 'node:buffer': require.resolve('buffer/'), |
| 26 | + path: require.resolve('path-browserify'), |
| 27 | + |
| 28 | + // Node.js core modules that need polyfills |
| 29 | + 'node:crypto': require.resolve('crypto-browserify'), |
| 30 | + 'node:url': require.resolve('url/'), |
| 31 | + 'node:util$': require.resolve('util/'), |
| 32 | + 'node:assert': require.resolve('assert/'), |
| 33 | + 'node:events': require.resolve('events/'), |
| 34 | + 'node:zlib': require.resolve('browserify-zlib'), |
| 35 | + 'node:http': require.resolve('stream-http'), |
| 36 | + querystring: require.resolve('querystring-es3'), |
| 37 | + 'node:querystring': require.resolve('querystring-es3'), |
| 38 | + |
| 39 | + // Node.js modules that don't work in browser - stub them out |
| 40 | + 'node:util/types': path.resolve(__dirname, 'stubs/empty.js'), |
| 41 | + 'node:http2': path.resolve(__dirname, 'stubs/empty.js'), |
| 42 | + 'node:async_hooks': path.resolve(__dirname, 'stubs/empty.js'), |
| 43 | + 'node:net': path.resolve(__dirname, 'stubs/empty.js'), |
| 44 | + 'node:tls': path.resolve(__dirname, 'stubs/empty.js'), |
| 45 | + 'node:perf_hooks': path.resolve(__dirname, 'stubs/empty.js'), |
| 46 | + 'node:diagnostics_channel': path.resolve(__dirname, 'stubs/empty.js'), |
| 47 | + 'node:console': path.resolve(__dirname, 'stubs/empty.js'), |
| 48 | + 'node:worker_threads': path.resolve(__dirname, 'stubs/empty.js'), |
| 49 | + |
| 50 | + // File system modules that don't work in browser |
| 51 | + fs: path.resolve(__dirname, 'stubs/empty.js'), |
| 52 | + 'fs/promises': path.resolve(__dirname, 'stubs/empty.js'), |
| 53 | + child_process: path.resolve(__dirname, 'stubs/empty.js'), |
| 54 | + module: path.resolve(__dirname, 'stubs/empty.js'), |
| 55 | + |
| 56 | + // Optional dependency that's not needed |
| 57 | + typescript: path.resolve(__dirname, 'stubs/empty.js'), |
| 58 | + |
| 59 | + // Problematic dependencies - use specific stubs |
| 60 | + prettier: path.resolve(__dirname, 'stubs/empty.js'), |
| 61 | + cosmiconfig: path.resolve(__dirname, 'stubs/empty.js'), |
| 62 | + htmlnano: path.resolve(__dirname, 'stubs/htmlnano.js'), |
| 63 | + |
| 64 | + // Undici is not needed in browser - stub it out completely |
| 65 | + undici: path.resolve(__dirname, 'stubs/empty.js'), |
40 | 66 | }, |
41 | 67 | }, |
| 68 | + node: { |
| 69 | + // Webpack 4 way to disable Node.js polyfills |
| 70 | + fs: 'empty', |
| 71 | + child_process: 'empty', |
| 72 | + worker_threads: false, |
| 73 | + net: 'empty', |
| 74 | + tls: 'empty', |
| 75 | + }, |
42 | 76 | module: { |
| 77 | + exprContextCritical: false, |
43 | 78 | rules: [ |
44 | 79 | { |
45 | | - test: /\.js$/, |
46 | | - exclude: path.join(__dirname, 'node_modules'), |
47 | | - use: [ |
48 | | - { |
49 | | - loader: 'babel-loader', |
50 | | - options: { |
51 | | - presets: [ |
| 80 | + test: /\.(js|mjs)$/, |
| 81 | + exclude: |
| 82 | + /node_modules\/(?!(cheerio|htmlparser2|domhandler|dom-serializer|domelementtype|domutils|entities|parse5|encoding-sniffer)\/).*/, |
| 83 | + use: { |
| 84 | + loader: 'babel-loader', |
| 85 | + options: { |
| 86 | + presets: [ |
| 87 | + [ |
52 | 88 | '@babel/preset-env', |
| 89 | + { |
| 90 | + targets: { browsers: ['> 0.25%', 'not dead'] }, |
| 91 | + }, |
53 | 92 | ], |
54 | | - plugins: [ |
55 | | - ["@babel/plugin-proposal-decorators", { "legacy": true }], |
56 | | - ["@babel/plugin-proposal-class-properties", { "loose" : true }], |
57 | | - "@babel/plugin-proposal-function-bind", |
58 | | - "@babel/plugin-proposal-export-default-from", |
59 | | - ], |
60 | | - babelrc: false, |
61 | | - }, |
| 93 | + ], |
| 94 | + plugins: [ |
| 95 | + 'lodash', |
| 96 | + '@babel/plugin-proposal-class-properties', |
| 97 | + '@babel/plugin-proposal-private-methods', |
| 98 | + '@babel/plugin-proposal-optional-chaining', |
| 99 | + '@babel/plugin-proposal-nullish-coalescing-operator', |
| 100 | + '@babel/plugin-proposal-logical-assignment-operators', |
| 101 | + ], |
62 | 102 | }, |
63 | | - ], |
| 103 | + }, |
64 | 104 | }, |
65 | | - ], |
| 105 | + ], |
| 106 | + }, |
| 107 | + optimization: { |
| 108 | + minimizer: [ |
| 109 | + new UglifyJsPlugin({ |
| 110 | + parallel: true, |
| 111 | + sourceMap: false, |
| 112 | + uglifyOptions: { |
| 113 | + compress: { |
| 114 | + drop_console: false, |
| 115 | + }, |
| 116 | + output: { |
| 117 | + comments: false, |
| 118 | + }, |
| 119 | + }, |
| 120 | + }), |
| 121 | + ], |
66 | 122 | }, |
| 123 | + plugins: [ |
| 124 | + new webpack.DefinePlugin({ |
| 125 | + 'process.env.NODE_ENV': JSON.stringify('production'), |
| 126 | + 'process.env': JSON.stringify({}), |
| 127 | + 'process.version': JSON.stringify('v18.0.0'), |
| 128 | + 'process.versions.node': JSON.stringify('18.0.0'), |
| 129 | + 'process.platform': JSON.stringify('browser'), |
| 130 | + }), |
| 131 | + new webpack.ProvidePlugin({ |
| 132 | + process: 'process/browser', |
| 133 | + Buffer: ['buffer', 'Buffer'], |
| 134 | + }), |
| 135 | + ], |
67 | 136 | } |
0 commit comments