Files
coriolis/webpack.common.js
Sam Clayton 875af31ffe Update to Webpack 5 (fixes crypto error on build) (#738)
* Updating react-number-editor dependency from stale named branch

* Remove references to deprecated react-addons-perf package

* Issue #25 Webpack updated to current version, many
dependencies updated, Babel & Webpack configs updated.
Add dev & prod Dockerfiles and update README with Docker instructions
Created webpack.common.js.
Coriolis-data now specified as github dependency

* Bump bugfix versions of react & react-dom only

* Workbox dependency upgrade for webpack 5 compat

* Stab at upgrading workbox dep
Far more fatal webpack errors :(

* Automate reinstall/rebuild with npm script

* Working build again w updated deps
Disabled/commented out all bugsnag references
Added production-like Docker build for troubleshooting issues that don't
 appear in dev server

* Remove deprecated @babel/polyfill import & dependency

* Fix to service worker to v5 of workbox
and align with webpack 5 plugin

* Disabling recent round of polyfills. Don't think
they're necessary.

* Whitespace in package.json

* Add Buffer as Webpack plugin. Fix indenting.
Fix deprecated call to Buffer.

* Remove bugsnag and deprecated babel code that was
 commented out, per convo with Felix

---------

Co-authored-by: Sam Clayton <sam@goranku.com>
2023-03-01 21:55:23 +01:00

82 lines
2.6 KiB
JavaScript

const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const pkgJson = require('./package');
const buildDate = new Date();
module.exports = {
entry: {
main: './src/app/index.js'
},
resolve: {
// When requiring, you don't need to add these extensions
extensions: ['.js', '.jsx', '.json', '.less'],
fallback: {
// Consider replacing brwoserify-zlib-next c. 2016 package with pako, which it's just a wrapper for
/* Some of these polyfills may not even be necessary, and were added in an attempt to deal with build issues
while upgrading to Webpack v5 */
"zlib": require.resolve("browserify-zlib-next"),
"assert": require.resolve("assert/"),
"buffer": require.resolve("buffer/"),
"stream": require.resolve("stream-browserify"),
/*
"url": require.resolve("url/"),
"path": require.resolve("path-browserify"),
"crypto": require.resolve("crypto-browserify"),
"os": require.resolve("os-browserify/browser"),
"https": require.resolve("https-browserify"),
"http": require.resolve("stream-http"),
"vm": require.resolve("vm-browserify"),
"constants": require.resolve("constants-browserify"),
// "fs": false
*/
}
},
optimization: {
usedExports: true
},
output: {
path: path.join(__dirname, 'build'),
chunkFilename: '[name].bundle.js',
// assetModuleFilename: '[contenthash][ext]',
publicPath: '/',
clean: true // we already do rimraf on the build dir, but this should obviate that
},
plugins: [
// new webpack.optimize.CommonsChunkPlugin({
// name: 'lib',
// filename: 'lib.js'
// }),
new HtmlWebpackPlugin({
inject: true,
template: path.join(__dirname, 'src/index.ejs'),
version: pkgJson.version,
// gapiKey: process.env.CORIOLIS_GAPI_KEY || '',
date: buildDate,
}),
new MiniCssExtractPlugin({
filename: 'app.css',
}),
// Solve missing Buffer polyfill that breaks module engineering
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
],
module: {
rules: [
{ test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader' ]},
{
test: /\.less$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'less-loader' ]
},
{ test: /\.(js|jsx)$/, use: ['babel-loader'], include: path.join(__dirname, 'src') },
{
test: /\.(jpe?g|svg|png|gif|ico|eot|ttf|woff|woff2?)(\?v=\d+\.\d+\.\d+)?$/i,
type: 'asset/resource',
},
]
}
};