Как я могу определить глобальные переменные в веб-пакете? - PullRequest
1 голос
/ 16 апреля 2020

Я новичок в вебпаке.

Пытаюсь сделать сборку с помощью веб-пакета. Все в порядке, ошибок нет, но когда я пытаюсь запустить код в браузере, он говорит:

build. js: 118 Uncaught ReferenceError: outputValues ​​не определено в countIntegers (build. js : 118) в модуле. (сборка js: 104) в webpack_require (сборка. js: 20) в сборке. js: 84 в сборке. js: 87

Итак, как я могу определить свои глобальные переменные в веб-пакете?

// index. js

(() => {
'use strict';})();

const outputValues = document.querySelectorAll('.output-values')[0];
const countButton = document.querySelectorAll('.count-button')[0];
const resetButton = document.querySelectorAll('.reset-button-disabled')[0];

import { countIntegers } from './button.js';

const counter = countIntegers();

countButton.addEventListener('click', counter.showNextInteger);
resetButton.addEventListener('click', counter.reset);

// button. js

export const countIntegers = () => {
  let currentInteger = 0;
    outputValues.innerText = currentInteger;
      return {
        showNextInteger: () => {
         if(currentInteger + 1 > 0) {
           resetButton.style.cursor = 'pointer';
           resetButton.disabled = false;
           resetButton.className = 'reset-button-enabled';
          }
            return outputValues.innerText = ++currentInteger;
        },
        reset: () => {
          outputValues.innerText = 0;
          resetButton.style.cursor = 'default';
          resetButton.disabled = true;
          resetButton.className = 'reset-button-disabled';
            return currentInteger = 0;
        }
      };
}

// webpack.config

const path = require('path');

module.exports = {

    entry: './assets/output/scripts/index.js',

    mode: 'none',

    output: {
        filename: 'build.js',
        path: path.join(__dirname, "/assets/bundle")
    }
};

Спасибо за помощь!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...