webpack.base.conf.js 3.3 KB

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