gristlabs_grist-core/buildtools/webpack.config.js
Paul Fitzpatrick f7f76fb5e7
A set of tweaks to simplify electron packaging (#421)
* Replace `ormconfig.js` with a newer mechanism of configuring
    TypeORM that can be included in the source code properly.
    The path to `ormconfig.js` has always been awkward to handle,
    and eliminating the file makes building different Grist setups
    a bit simpler.
  * Remove `electron` package. It is barely used, just for some old
    remnants of an older attempt at electron packaging. It was used
    for two types, which I left at `any` for now. More code pruning is
    no doubt possible here, but I'd rather do it when Electron packaging
    has solidified.
  * Add a hook for replacing the login system, and for adding some
    extra middleware the login system may need.
  * Add support for some more possible locations of Python, which
    arise when a standalone version of it is included in the Electron
    package. This isn't very general purpose, just configurations
    that I found useful.
  * Support using grist-core within a yarn workspace - the only tweak
    needed was webpack related.
  * Allow an external ID to be optionally associated with documents.
2023-02-13 15:52:17 -05:00

82 lines
2.7 KiB
JavaScript

const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
const { ProvidePlugin } = require('webpack');
const path = require('path');
// Get path to top-level node_modules if in a yarn workspace.
// Otherwise node_modules one level up won't get resolved.
// This is used in Electron packaging.
const base = path.dirname(path.dirname(require.resolve('grainjs/package.json')));
module.exports = {
target: 'web',
entry: {
main: "app/client/app",
errorPages: "app/client/errorMain",
account: "app/client/accountMain",
billing: "app/client/billingMain",
activation: "app/client/activationMain",
},
output: {
filename: "[name].bundle.js",
sourceMapFilename: "[file].map",
path: path.resolve("./static"),
// Workaround for a known issue with webpack + onerror under chrome, see:
// https://github.com/webpack/webpack/issues/5681
// "We use a source map plugin here with this special configuration
// because if we do not - the window.onerror function does not work properly in chrome
// and it swallows the errors because normally source maps have begin with webpack:///
// here we are changing how the module file names are created
// See this bug
// https://bugs.chromium.org/p/chromium/issues/detail?id=765909
// See this for syntax
// https://webpack.js.org/configuration/output/#output-devtoolmodulefilenametemplate
// "
devtoolModuleFilenameTemplate: "[resourcePath]?[loaders]",
crossOriginLoading: "anonymous",
},
// This creates .map files, and takes webpack a couple of seconds to rebuild while developing,
// but provides correct mapping back to typescript, and allows breakpoints to be set in
// typescript ("cheap-module-eval-source-map" is faster, but breakpoints are largely broken).
devtool: "source-map",
resolve: {
extensions: ['.ts', '.js'],
modules: [
path.resolve('.'),
path.resolve('./ext'),
path.resolve('./stubs'),
path.resolve('./node_modules'),
base,
],
fallback: {
'path': require.resolve("path-browserify"),
},
},
module: {
rules: [
{
test: /\.(js|ts)?$/,
loader: 'esbuild-loader',
options: {
loader: 'ts',
target: 'es2017',
sourcemap: true,
},
exclude: /node_modules/
},
{ test: /\.js$/,
use: ["source-map-loader"],
enforce: "pre"
}
]
},
plugins: [
// Some modules assume presence of Buffer and process.
new ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer']
}),
// To strip all locales except “en”
new MomentLocalesPlugin()
],
};