I connect libraries through one file by copying the minified code alternately into one file and then I connect it only to index.html. If you do it right, then everything works, but when I started to build the project through the webpack, I started issuing type errors (in jQuery):

Uncaught ReferenceError: $ is not defined at Object.149 (common.js:sourcemap:826) at __webpack_require__ (common.js:sourcemap:679) at fn (common.js:sourcemap:89) at Object.148 (common.js:sourcemap:815) at __webpack_require__ (common.js:sourcemap:679) at 1.logLevel (common.js:sourcemap:725) at common.js:sourcemap:728 

Which means that the library did not connect.

Here is the code for webpack.config.js:

  const ExtractTextPlugin = require('extract-text-webpack-plugin'); var webpack = require('webpack'); var path = require('path'); module.exports = { context: __dirname, entry: { bundle: "./src/index.jsx", common: "./src/js/common.js", libs: "./src/js/libs.js", main_gmaps: "./src/js/main_gmaps.js" }, output: { path: __dirname + '/public', filename: "[name].js", publicPath: '/public/' }, module: { loaders: [ { test: /\.js|.jsx?$/, exclude: /(node_modules)/, loader: 'babel-loader', query: { presets: ['react', 'es2015'] } }, { test: /\.sass$/, loader: ExtractTextPlugin.extract('css-loader!sass-loader?sourceMap') }, { test: /\.(png|jpg|jpeg|svg|gif)$/, include: [ path.resolve(__dirname, './src/img/') // а тут надо прописать имя папки откуда будет брать все картинки ], use: [{ loader: 'file-loader', options: { name: './public/img/[hash].[ext]', } }] } ] }, resolve: { extensions: ['.js', '.jsx'], }, plugins: [ new ExtractTextPlugin({ filename: 'app.css', allChunks: true }) ], devServer: { historyApiFallback: true, contentBase: './' } }; 

How to fix this error. Thank!

  • A about package.json and npm install heard? - Mikhail Chibel

1 answer 1

Alternatively, connect jquery via webpack.ProvidePlugin

In the config in the plugins section, you will need to add:

 plugins: [ new webpack.ProvidePlugin({ $ : 'jquery' }), ],