Giter Club home page Giter Club logo

Comments (5)

amitayr avatar amitayr commented on June 11, 2024 2

@cdauth this happens because of javascript hoisting.
this line:
var window = (window || {});
is interpreted as
var window; window = (window || {});
so you don't get the global window varaible.

you can solve it with some hacking:
imports-loader?window=>global&window.jQuery=>jquery!angular
or
imports-loader?windowTemp=>window&windowTemp.jQuery=>jquery!angular

from imports-loader.

cdauth avatar cdauth commented on June 11, 2024

I am using exactly the same expression, but for me the imports-loader additionally inserts the some code into the angular module itself:

/* 5 */
/***/ function(module, exports, __webpack_require__) {

	/*** IMPORTS FROM imports-loader ***/
	var window = (window || {});
	window.jQuery = __webpack_require__(3);

	/**
	 * @license AngularJS v1.6.1
	 * (c) 2010-2016 Google, Inc. http://angularjs.org
	 * License: MIT
	 */
	(function(window) {'use strict';

For some reason though, this window object is broken and for example doesn't contain document. I don't really understand why, I will try to investigate.

from imports-loader.

Lazarencjusz avatar Lazarencjusz commented on June 11, 2024

You can provide jQuery by adding plugin:

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

from imports-loader.

cap-Bernardito avatar cap-Bernardito commented on June 11, 2024

After the release, you can solve this problem like this:

module.exports = {
  module: {
    rules: [
      {
        test: require.resolve('example.js'),
        use: [
          {
            loader: 'imports-loader',
            options: {
              type: 'commonjs',
              imports: {
                moduleName: 'jquery',
                name: 'jQuery',
              },
              aditionalCode: 'window.jQuery = jQuery';
            },
          },
        ],
      },
    ],
  },
};

// Adds the following code to the beginning of example.js:
//
// var jQuery = require("jquery");
// window.jQuery = jQuery

Release will be soon.

from imports-loader.

Tchiller avatar Tchiller commented on June 11, 2024

@cap-Bernardito thanks for your last comment. There is a little typo in it which you might want to correct. "additionalCode"

Thank you.

from imports-loader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.