You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.4 KiB

  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const HtmlWebpackPlugin = require('html-webpack-plugin');
  4. const CleanWebpackPlugin = require('clean-webpack-plugin');
  5. const entryList = {
  6. dashboard: './src/dashboard/index.js',
  7. style: './src/styles/index.scss',
  8. login_style: './src/styles/login.scss',
  9. order_detail: './src/detail-display/index.js',
  10. sku: './src/sku/index.js',
  11. mini_program_management: './src/mini-program-management/index.js',
  12. spread: './src/spread/index.js',
  13. sku_item: './src/sku-item/index.js',
  14. 'custom-menu': './src/custom-menu/index.js',
  15. sku_for_activity: './src/sku-for-activity/index.js',
  16. };
  17. const needIconfontEntries = ['style', 'login_style'];
  18. module.exports = function (env, argv) {
  19. const pathToClean = argv.module ? `${argv.module}.*.js` : 'custom';
  20. const entry = argv.module ? {[argv.module]: entryList[argv.module]} : entryList;
  21. const htmlWebpackPluginList = Object.keys(entry).map(entryItem => new HtmlWebpackPlugin({
  22. filename: `${entryItem}.html`,
  23. chunks: [entryItem],
  24. template: needIconfontEntries.includes(entryItem) ? 'src/iconfont.html' : 'src/import.html'
  25. }));
  26. return {
  27. entry,
  28. output: {
  29. filename: '[name].[chunkhash].js',
  30. path: path.resolve(__dirname, 'custom'),
  31. publicPath: '/custom/'
  32. },
  33. module: {
  34. rules: [
  35. {
  36. test: /\.js$/,
  37. exclude: /(node_modules|bower_components)/,
  38. use: {
  39. loader: 'babel-loader'
  40. }
  41. },
  42. {
  43. test: /\.scss$/,
  44. use: ["style-loader", "css-loader", "resolve-url-loader", "sass-loader?sourceMap",
  45. {
  46. loader: 'sass-resources-loader',
  47. options: {
  48. resources: './src/styles/variables.scss'
  49. }
  50. }]
  51. },
  52. {
  53. test: /\.css$/,
  54. use: ["style-loader", "css-loader"]
  55. },
  56. {
  57. test: /\.(png|jpg|gif|eot|svg|ttf|woff2?)(\?.*)?$/i,
  58. use: [
  59. {
  60. loader: 'url-loader',
  61. options: {
  62. limit: 10000
  63. }
  64. },
  65. 'file-loader'
  66. ]
  67. }
  68. ]
  69. },
  70. plugins: [
  71. new CleanWebpackPlugin({
  72. cleanOnceBeforeBuildPatterns: [pathToClean]
  73. }),
  74. new webpack.DefinePlugin({
  75. ENV_DEV: JSON.stringify(argv.mode === 'development')
  76. }),
  77. ...htmlWebpackPluginList,
  78. ]
  79. };
  80. };