webpack.base.conf.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. 'use strict'
  2. const webpack = require('webpack')
  3. const path = require('path')
  4. const utils = require('./utils')
  5. const config = require('../config')
  6. const vueLoaderConfig = require('./vue-loader.conf')
  7. //头部引入css打包插件
  8. const ExtractTextPlugin = require("extract-text-webpack-plugin");
  9. var projectRoot = path.resolve(__dirname, '../')
  10. function resolve (dir) {
  11. return path.join(__dirname, '..', dir)
  12. }
  13. module.exports = {
  14. entry: {
  15. app: ['babel-polyfill','./src/main.js'],
  16. },
  17. plugins: [
  18. new webpack.ProvidePlugin({
  19. $: "jquery",
  20. jQuery:"jquery",
  21. "window.jQuery":"jquery"
  22. }),
  23. ],
  24. output: {
  25. path: config.build.assetsRoot,
  26. filename: '[name].js',
  27. publicPath: process.env.NODE_ENV === 'production'
  28. ? config.build.assetsPublicPath
  29. : config.dev.assetsPublicPath
  30. },
  31. resolve: {
  32. extensions: ['.js', '.vue', '.json'],
  33. alias: {
  34. 'vue$': 'vue/dist/vue.esm.js',
  35. 'alte':'admin-lte/dist',
  36. 'alt-plugin':'admin-lte/plugins',
  37. '@': resolve('src')
  38. }
  39. },
  40. module: {
  41. rules: [
  42. {
  43. test: /\.vue$/,
  44. use:[{
  45. loader: 'vue-loader',
  46. options: vueLoaderConfig
  47. },{
  48. loader: 'iview-loader',
  49. options: {
  50. prefix: false
  51. }
  52. }]
  53. },
  54. {
  55. test: /\.js$/,
  56. loader: 'babel-loader',
  57. include: projectRoot,
  58. exclude: /node_modules/
  59. },
  60. //{
  61. // test: /\.css$/,
  62. // //请注意loader里的写法,有一些低版本的例子中是过时的写法
  63. // loader: ExtractTextPlugin.extract({
  64. // fallback: "style-loader",
  65. // use: "css-loader"
  66. // })
  67. //},
  68. {
  69. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  70. loader: 'url-loader',
  71. options: {
  72. limit: 10000,
  73. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  74. }
  75. },
  76. {
  77. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  78. loader: 'url-loader',
  79. options: {
  80. limit: 10000,
  81. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  82. }
  83. },
  84. {
  85. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  86. loader: 'url-loader',
  87. options: {
  88. limit: 10000,
  89. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  90. }
  91. }
  92. ]
  93. },
  94. externals: {
  95. /**
  96. * webpack 中的 externals 配置提供了不从 bundle 中引用依赖的方式。
  97. * 解决的是,所创建的 bundle 依赖于那些存在于用户环境(consumer environment)中的依赖。
  98. */
  99. // 'jquery': 'jQuery',
  100. //'vue': 'Vue',
  101. echarts: 'echarts',
  102. }
  103. }