webpack.base.conf.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. 'use strict';
  2. const path = require('path');
  3. const resolve = function (src) {
  4. return path.resolve(__dirname, src);
  5. };
  6. const config = require('../config');
  7. const utils = require('./utils');
  8. process.noDeprecation = true;
  9. const env = process.env.NODE_ENV;
  10. const urlPath = env === 'production' ? utils.assetsPath('img/[name].[hash:7].[ext]') : "img/[name].[hash:7].[ext]";
  11. const fontPath = env === 'production' ? utils.assetsPath('font/[name].[hash:7].[ext]') : "font/[name].[hash:7].[ext]";
  12. module.exports = {
  13. entry: {
  14. main:['./src/main.js']
  15. },// 配置需要打包的入口文件
  16. output: {
  17. path: config.build.assetsRoot,// 输出文件根目录
  18. filename: '[name].js',//输出文件路径和名字
  19. publicPath: env === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath
  20. },
  21. resolve: {
  22. extensions: [".js",'.jsx',".json"],
  23. alias: {
  24. '@': resolve('../src'),
  25. '@src': resolve('../src'),
  26. '@common': resolve('../src/common'),
  27. '@commonComp': resolve('../src/common/components'),
  28. '@less': resolve('../src/common/less'),
  29. '@mixin': resolve('../src/common/less/mixin.less'),
  30. '@images': resolve('../src/common/images'),
  31. '@components': resolve('../src/components'),
  32. '@containers': resolve('../src/containers'),
  33. '@modules': resolve('../src/module'),
  34. '@mock': resolve('../src/mock/'),
  35. '@utils': resolve('../src/utils'),
  36. '@lib': resolve('../src/lib'),
  37. '@store': resolve('../src/store'),
  38. '@asyncActions': resolve('../src/store/async-actions'),
  39. '@actions': resolve('../src/store/actions'),
  40. '@reducers': resolve('../src/store/reducers'),
  41. '@types': resolve('../src/store/types'),
  42. '@config':resolve('../src/config')
  43. }
  44. },
  45. module: {
  46. rules: [
  47. {
  48. test: /\.(js|jsx)$/,
  49. loader: 'babel-loader',
  50. exclude: /node_modules/
  51. },
  52. {
  53. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  54. loader: 'url-loader',
  55. options: {
  56. limit: 8196,
  57. publicPath: '../../',
  58. name:urlPath,
  59. }
  60. },
  61. {
  62. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  63. loader: 'url-loader',
  64. options: {
  65. limit: 8196,
  66. publicPath: '../../',
  67. name:fontPath,
  68. }
  69. }
  70. ]
  71. }
  72. };