webpack.config.js
'use strict';
let path = require('path');
module.exports = {
mode: 'development',
entry: './src/js/script.js',
output: {
filename: 'bundle.js',
path: __dirname + './dist/js'
},
watch: true,
devtool: "source-map",
module: {}
};
package.json
{
"name": "kredo-bet",
"version": "1.0.0",
"main": "gulpfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.26.12",
"gulp": "^4.0.2",
"gulp-autoprefixer": "^6.1.0",
"gulp-clean-css": "^4.3.0",
"gulp-cli": "^2.3.0",
"gulp-htmlmin": "^5.0.1",
"gulp-imagemin": "^6.2.0",
"gulp-rename": "^1.4.0",
"gulp-sass": "^4.1.0",
"webpack": "^5.42.1",
"webpack-cli": "^4.7.2"
},
"browserslist": [
"last 1 version",
"> 1%",
"maintained node versions",
"not dead"
],
"description": "",
"dependencies": {}
}
menu.js
function hamburgerNenu() {
const hamburger = document.querySelector('.header__gamburger'),
closeElem = document.querySelector('.menu__toggle'),
menu = document.querySelector('.menu');
hamburger.addEventListener('click', () => {
menu.classList.add('active');
});
closeElem.addEventListener('click', () => {
menu.classList.remove('active');
});
}
export default hamburgerNenu;
script.js
import hamburger from './modules/menu';
hamburger();
Ошибка выглядит так:
Error: For the selected environment is no default script chunk format available:
JSONP Array push can be chosen when 'document' or 'importScripts' is available.
CommonJs exports can be chosen when 'require' or node builtins are available.
Make sure that your 'browserslist' includes only platforms that support these features or select an appropriate 'target' to allow selecting a chunk format by default. Alternatively specify the 'output.chunkFormat' directly.
at E:\work\kredo-bet\node_modules\webpack\lib\config\defaults.js:669:11
at F (E:\work\kredo-bet\node_modules\webpack\lib\config\defaults.js:71:15)
at applyOutputDefaults (E:\work\kredo-bet\node_modules\webpack\lib\config\defaults.js:650:2)
at applyWebpackOptionsDefaults (E:\work\kredo-bet\node_modules\webpack\lib\config\defaults.js:182:2)
at createCompiler (E:\work\kredo-bet\node_modules\webpack\lib\webpack.js:78:2)
at create (E:\work\kredo-bet\node_modules\webpack\lib\webpack.js:127:16)
at webpack (E:\work\kredo-bet\node_modules\webpack\lib\webpack.js:135:47)
at WebpackCLI.f [as webpack] (E:\work\kredo-bet\node_modules\webpack\lib\index.js:55:16)
at WebpackCLI.createCompiler (E:\work\kredo-bet\node_modules\webpack-cli\lib\webpack-cli.js:2053:29)
at async WebpackCLI.buildCommand (E:\work\kredo-bet\node_modules\webpack-cli\lib\webpack-cli.js:2173:20)0)