如何查看webpack引入依赖库的位置(哪个文件)

我在*.vue,main.js中都没有引入jquery。但是用 webpack-bundle-size-analyzer 分析bundle文件的时候,显示jquery已经引入了依赖:


$ webpack --json | webpack-bundle-size-analyzer
vue: 274.93 KB (26.7%)
jquery: 261.76 KB (25.4%)
webuploader: 254.54 KB (24.7%)
buffer: 47.47 KB (4.61%)
axios: 36.19 KB (3.52%)
cuint: 24.69 KB (2.40%)
xxhashjs: 20.97 KB (2.04%)
vue-style-loader: 6.54 KB (0.635%)
setimmediate: 6.32 KB (0.614%)
process: 5.29 KB (0.514%)
base64-js: 3.39 KB (0.329%)
vue-loader: 2.83 KB (0.275%)
css-loader: 2.21 KB (0.214%)
ieee754: 2.01 KB (0.195%)
timers-browserify: 1.33 KB (0.129%)
is-buffer: 698 B (0.0662%)
webpack: 488 B (0.0463%)
isarray: 132 B (0.0125%)
<self>: 77.6 KB (7.54%)

main.js:


//import 'babel-polyfill';
import Vue from 'vue'
import ImageUpload from './ImageUpload.vue'
import AttachUpload from './AttachUpload.vue'
import Draggable from './directives/draggable'
Vue.component('imageupload',ImageUpload);
Vue.component('attachupload',AttachUpload);
Vue.directive('draggable',Draggable);
//var jQuery = window.jQuery;
new Vue({
  el: '#app',
  //render: h => h(App)
});

webpack.config.js:


var path = require('path')
var webpack = require('webpack')

module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
          }
          // other vue-loader options go here
        }
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    }
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true
  },
  performance: {
    hints: false
  },
  devtool: '#eval-source-map'
}

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      sourceMap: true,
      compress: {
        warnings: false
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ])
}


阅读 5.1k
1 个回答

yarn有个命令,可以查看某个包的依赖关系 用法如下yarn why <package-name>,比如你这个只要在项目的根目录下执行yarn why jquery,就可在知道是哪个包引入了jquery,前提是你安装了yarn

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题