ProvidePlugin с предварительной конфигурацией - PullRequest
0 голосов
/ 27 мая 2020

Я хочу предоставить плагин, использующий webpack.ProvidePlugin. В предыдущей версии моего проекта мне удалось предоставить его с помощью этой конфигурации Webpack:

module.exports = {
  webpack: {
    plugins: [
      new webpack.ProvidePlugin({
        PIXI: 'pixi.js',
      }),
    ],
  },
};

Однако, похоже, я не могу получить тот же результат через файл preact.config.js:

webpack(config, env, helpers, options) {
  /**
  * Function that mutates the original webpack config.
  * Supports asynchronous changes when a promise is returned (or it's an async function).
  *
  * @param {object} config - original webpack config.
  * @param {object} env - options passed to the CLI.
  * @param {WebpackConfigHelpers} helpers - object with useful helpers for working with the webpack config.
  * @param {object} options - this is mainly relevant for plugins (will always be empty in the config), default to an empty object
  **/
  // ...
  options = {
    plugins: [
      new webpack.ProvidePlugin({
        PIXI: "pixi.js",
      })
    ]
  }
}

Это возвращает ReferenceError: PIXI is not defined во время выполнения, что является ошибкой, которую я получил в моем раннем проекте, когда я не предоставлял плагин через метод ProvidePlugin. Как мне установить preact.config.js, чтобы он правильно предоставлял плагин?

...