webpack.base.conf.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. const CleanWebpackPlugin = require("clean-webpack-plugin")
  10. var projectRoot = path.resolve(__dirname, '../')
  11. function resolve (dir) {
  12. return path.join(__dirname, '..', dir)
  13. }
  14. module.exports = function(baseOption)
  15. {
  16. return {
  17. entry: {
  18. app: ['babel-polyfill','./src/main.js'],
  19. },
  20. plugins: [
  21. new webpack.ProvidePlugin({
  22. $: "jquery",
  23. jQuery:"jquery",
  24. "window.jQuery":"jquery"
  25. }),
  26. new CleanWebpackPlugin(
  27. ['dist/*'],  //匹配删除的文件
  28. {
  29. root: path.resolve(__dirname, '../'),           //根目录
  30. verbose: true,           //开启在控制台输出信息
  31. dry: false           //启用删除文件
  32. }
  33. ),
  34. ],
  35. output: {
  36. path: config.build.assetsRoot,
  37. filename: '[name].js',
  38. publicPath: process.env.NODE_ENV === 'production'
  39. ? config.build.assetsPublicPath
  40. : config.dev.assetsPublicPath
  41. },
  42. resolve: {
  43. extensions: ['.js', '.vue', '.json'],
  44. alias: {
  45. 'vue$': 'vue/dist/vue.esm.js',
  46. 'alte':'admin-lte/dist',
  47. 'alt-plugin':'admin-lte/plugins',
  48. '@': resolve('src')
  49. }
  50. },
  51. module: {
  52. rules: [
  53. {
  54. test: /\.vue$/,
  55. use:[{
  56. loader: 'vue-loader',
  57. options: vueLoaderConfig(baseOption)
  58. },{
  59. loader: 'iview-loader',
  60. options: {
  61. prefix: false
  62. }
  63. }]
  64. },
  65. {
  66. test: /\.js$/,
  67. loader: 'babel-loader',
  68. include: [projectRoot,resolve('/node_modules/iview/src/components/table/expand.js')],
  69. exclude: /node_modules/
  70. },
  71. //{
  72. // test: /\.css$/,
  73. // //请注意loader里的写法,有一些低版本的例子中是过时的写法
  74. // loader: ExtractTextPlugin.extract({
  75. // fallback: "style-loader",
  76. // use: "css-loader"
  77. // })
  78. //},
  79. {
  80. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  81. loader: 'url-loader',
  82. options: {
  83. limit: 10000,
  84. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  85. }
  86. },
  87. {
  88. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  89. loader: 'url-loader',
  90. options: {
  91. limit: 10000,
  92. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  93. }
  94. },
  95. {
  96. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  97. loader: 'url-loader',
  98. options: {
  99. limit: 10000,
  100. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  101. }
  102. }
  103. ]
  104. }
  105. }
  106. }