Webpack - 在webpack.config.json中使用Script Loader

use*_*757 6 javascript webpack

我刚刚开始把我的脚趾浸入webpack的世界.我使用了很棒的Vue.js和vueify,因此我的模块是ES6.

我遇到的一个难点是加载一些第三方jQuery插件.我使用ProvidePlugin加载jQuery - 工作正常.

plugins: [
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery"
        })
    ]
Run Code Online (Sandbox Code Playgroud)

然后我有一个名为plugins的目录,其中包含misc jQuery插件.我的理解是脚本加载器只是将它们作为字符串加载到捆绑文件中,并在捆绑加载时进行评估.然后可以使用这些脚本,就像它们被加载到常规脚本标记中一样(即,不需要导入).

但我不能让任何插件工作.下面是我的加载器数组.我做错了什么(或没做错)?

loaders: [

        // process *.vue files using vue-loader
        {
            test: /\.vue$/,
            loader: 'vue'
        },
        // process *.js files using babel-loader
        // the exclude pattern is important so that we don't
        // apply babel transform to all the dependencies!
        {
            test: /\.js$/,
            loader: 'babel',
            exclude: /node_modules/
        },
        {
            test: /plugins\.js$/,
            loader: 'script-loader' #tried script too
        }

    ]
Run Code Online (Sandbox Code Playgroud)

小智 0

new webpack.ProvidePlugin({
  'React': path.resolve(__dirname, "node_modules/react/react"),
  'ReactDOM': path.resolve(__dirname, "node_modules/react-dom/dist/react-dom"),
  "jQuery": path.resolve(__dirname, "node_modules/jquery/dist/jquery"),
  "$": path.resolve(__dirname, "node_modules/jquery/dist/jquery")
})
Run Code Online (Sandbox Code Playgroud)

解决你的lib路径