A
A
Alexander Ivanov2019-05-24 16:27:13
webpack
Alexander Ivanov, 2019-05-24 16:27:13

How to install jquery in webpack?

Trying to install jquery via webpack
webpack.config.js

"use strict"
const path = require('path')
const webpack = require('webpack')

module.exports = {
  plugins: [
    new webpack.ProvidePlugin({
    $: "jquery",
    jQuery: "jquery"
    }),
  ]
};

pckage.json
{
  "name": "mp",
  "version": "2.0.0",
  "description": "Веб модуль с привязкой жителей к жилым зданиям",
  "main": "index.js",
  "scripts": {
    "dev": "webpack --mode development",
    "build": "webpack --mode production",
    "watch": "webpack --mode development --watch",
    "start": "webpack-dev-server --mode development --open"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/AlexandrRumiantsev/app_map.git"
  },
  "keywords": [
    "6Exniskay20"
  ],
  "author": "AlexWeber",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/AlexandrRumiantsev/app_map/issues"
  },
  "homepage": "https://github.com/AlexandrRumiantsev/app_map#readme",
  "devDependencies": {
    "clean-webpack-plugin": "^1.0.0",
    "css-loader": "^2.0.0",
    "file-loader": "^2.0.0",
    "html-webpack-plugin": "^3.2.0",
    "image-webpack-loader": "^4.6.0",
    "jquery": "^3.4.1",
    "mini-css-extract-plugin": "^0.5.0",
    "node-sass": "^4.10.0",
    "optimize-css-assets-webpack-plugin": "^5.0.1",
    "sass-loader": "^7.1.0",
    "webpack": "^4.27.1",
    "webpack-cli": "^3.1.2"
  },
  "dependencies": {
    "bootstrap": "^4.3.1",
    "jquery": "^3.3.1",
    "popper.js": "^1.15.0",
    "webpack-jquery-ui": "^2.0.1"
  }
}

index.js which I run through the command line with the command node index.js
(function(){
  "use strict";
import $ from 'jquery';
$(document).ready(function($) {
  console.log('СЕРВЕР ЗАПУЩЕН'); 
});
})();

Result: import $ from 'jquery'; - SyntaxError: Unexpected identifier
QUESTION: What does the error mean I KNOW, can't figure out why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2019-05-24
@Xuxicheta

why do you node index.jsneed it when you need it npm run startfor development and npm run buildfor building sales.
node index.jslaunches the node with the index.js file, the node does not understand imports and gives an error.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question