TidGi-Desktop/webpack.plugins.js
林一二 e8b36edd1c fix: Webpack has been initialized using a configuration object that does not match the API schema
An unhandled error has occurred inside Forge:
Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.plugins[6] should be one of these:
   object { apply, … } | function
   -> Plugin of type object or instanceof Function.
   Details:
    * configuration.plugins[6] should be an object:
      object { apply, … }
      -> Plugin instance.
    * configuration.plugins[6] should be an instance of function.
      -> Function acting as plugin.
ValidationError: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.plugins[6] should be one of these:
   object { apply, … } | function
   -> Plugin of type object or instanceof Function.
   Details:
    * configuration.plugins[6] should be an object:
      object { apply, … }
      -> Plugin instance.
    * configuration.plugins[6] should be an instance of function.
      -> Function acting as plugin.

This is because there is an undefined in the plugins list

exports.renderer [
  DefinePlugin {
    definitions: { 'process.env.NODE_ENV': '"development"' }
  },
  CspHtmlWebpackPlugin {
    cspPluginPolicy: {
      'base-uri': [Array],
      'object-src': [Array],
      'script-src': [Array],
      'style-src': [Array],
      'frame-src': [Array],
      'worker-src': [Array]
    },
    opts: {
      enabled: true,
      hashingMethod: 'sha256',
      hashEnabled: [Object],
      nonceEnabled: [Object],
      processFn: [Function: defaultProcessFn]
    }
  },
  WebpackBarPlugin {
    profile: false,
    handler: [Function (anonymous)],
    modulesCount: 5000,
    dependenciesCount: 10000,
    showEntries: true,
    showModules: true,
    showDependencies: true,
    showActiveModules: true,
    percentBy: undefined,
    options: {
      name: 'webpack',
      color: 'green',
      reporters: [Array],
      reporter: null
    },
    reporters: [ FancyReporter {} ]
  },
  undefined
]
2021-08-07 19:57:26 +08:00

75 lines
2.7 KiB
JavaScript

/* eslint-disable unicorn/prefer-module */
/* eslint-disable @typescript-eslint/no-var-requires */
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const CspHtmlWebpackPlugin = require('csp-html-webpack-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const _ = require('lodash');
const path = require('path');
const fs = require('fs-extra');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const ThreadsPlugin = require('threads-plugin');
const ExternalsPlugin = require('webpack5-externals-plugin');
const EventHooksPlugin = require('event-hooks-webpack-plugin');
const WebpackBar = require('webpackbar');
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
exports.main = _.compact([
// we only need one instance of TsChecker, it will check main and renderer all together
new ForkTsCheckerWebpackPlugin(),
new CopyPlugin({
// to is relative to ./.webpack/main/
patterns: [{ from: 'localization', to: 'localization' }],
}),
new CircularDependencyPlugin({
// exclude detection of files based on a RegExp
exclude: /node_modules/,
// add errors to webpack instead of warnings
failOnError: true,
// allow import cycles that include an asyncronous import,
// e.g. via import(/* webpackMode: "weak" */ './file.js')
allowAsyncCycles: true,
// set the current working directory for displaying module paths
cwd: process.cwd(),
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': `"${process.env.NODE_ENV ?? 'production'}"`,
}),
new ExternalsPlugin({
type: 'commonjs',
include: path.join(__dirname, 'node_modules', '@tiddlygit', 'tiddlywiki'),
}),
new ThreadsPlugin({
target: 'electron-node-worker',
plugins: ['ExternalsPlugin'],
}),
new WebpackBar(),
]);
exports.renderer = _.compact([
new webpack.DefinePlugin({
'process.env.NODE_ENV': `"${process.env.NODE_ENV ?? 'production'}"`,
// global: {},
}),
new CspHtmlWebpackPlugin(
{
'base-uri': ["'self'"],
'object-src': ["'none'"],
'script-src': ["'self' 'unsafe-eval'"],
'style-src': ["'self' 'unsafe-inline'"],
'frame-src': ["'none'"],
'worker-src': ["'none'"],
},
{
nonceEnabled: {
'style-src': false,
},
},
),
new WebpackBar(),
process.env.NODE_ENV === 'production'
? // eslint-disable-next-line @typescript-eslint/no-unsafe-call
new BundleAnalyzerPlugin({ generateStatsFile: true, analyzerMode: 'disabled', statsFilename: '../../out/webpack-stats-renderer.json' })
: undefined,
]);