Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Bootstrap 3 - jQuery not defined #214

Closed
alvipeo opened this issue Jan 11, 2016 · 4 comments
Closed

Using Bootstrap 3 - jQuery not defined #214

alvipeo opened this issue Jan 11, 2016 · 4 comments

Comments

@alvipeo
Copy link

alvipeo commented Jan 11, 2016

I'm pretty new to webpack and I'd like to use Bootstrap 3. So I added bootstrap and jquery typings to the project but when I add

import 'bootstrap';

and then npm start server I get

'jQuery' is undefined (in console)

Could anyone help?

@PatrickJS
Copy link
Owner

you can also install and include jQuery

@alvipeo
Copy link
Author

alvipeo commented Jan 11, 2016

ok, found out. Just changed plugins section in webpack.config.js (added ProvidePlugin):

plugins: [
    new CommonsChunkPlugin({ name: 'vendor', filename: 'vendor.bundle.js', minChunks: Infinity }),
    // static assets
    new CopyWebpackPlugin([{ from: 'src/assets', to: 'assets' }]),
    // generating html
    new HtmlWebpackPlugin({ template: 'src/index.html', inject: false }),
    // replace
    new DefinePlugin({
        'process.env': {
            'ENV': JSON.stringify(metadata.ENV),
            'NODE_ENV': JSON.stringify(metadata.ENV)
        }
    }),
    new ProvidePlugin({    // <added>
        jQuery: 'jquery',
        $: 'jquery',
        jquery: 'jquery'   // </added>
    })
],

That resolved the issue. As far as I understand now when Bootstrap imported webpack knows where jQuery should come from. Correct?

@PatrickJS
Copy link
Owner

ya, that should work

@xiaoman627
Copy link

初学angular2比较难,有什么比较易学angular2的推荐吗?学习angular2怎么样比较容易?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants