webpack.base.conf.js 2.6 KB

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