Webpack没有捆绑jquery

时间:2017-09-07 15:51:29

标签: jquery webpack

我在VS2017中创建了一个Web应用程序(ASP.NET MVC Core,.NET 4.6) 并为visual studio安装了web包扩展

webpack.config.js:

"use strict"
{
    // Required to form a complete output path
    let path = require('path');
    var webpack = require('webpack');
    // Plugin for cleaning up the output folder (bundle) before creating a new one
    const CleanWebpackPlugin = require('clean-webpack-plugin');

    // Path to the output folder
    const bundleFolder = "wwwroot/bundle/";

    module.exports = {
        // Application entry point
        entry: "./app/main.ts",

        // Output file
        output: {
            filename: 'script.js',
            path: path.resolve(__dirname, bundleFolder)
        },
        module: {
            rules: [
                {
                    test: /\.tsx?$/,
                    loader: "ts-loader"
                },
            ],
        },
        resolve: {
            extensions: [".tsx", ".ts", ".js"],
            root: [
                path.resolve(__dirname, 'src'),
                path.resolve(__dirname, 'node_modules')

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

        ],
        // Include the generation of debugging information within the output file
        // (Required for debugging client scripts)
        devtool: "inline-source-map"
    };
}

jquery位于 ./ node_modules

我希望在 script.js 中看到捆绑的jquery代码,但它不存在

1 个答案:

答案 0 :(得分:1)

我不相信webpack会捆绑它,除非你真的在某个地方使用它。尝试将这样的内容添加到您的入口点(或它导入的模块):

console.log('jquery version:', jQuery.fn.jquery);

这应该让webpack将它添加到你的包中。