webpack.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * @author oldj
  3. * @blog http://oldj.net
  4. */
  5. 'use strict'
  6. const path = require('path')
  7. const webpack = require('webpack')
  8. const moment = require('moment')
  9. const WebpackNotifierPlugin = require('webpack-notifier')
  10. const ExtractTextPlugin = require('extract-text-webpack-plugin')
  11. const LESSPluginLists = require('less-plugin-lists')
  12. const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
  13. const version = require('../app/version').version.join('.')
  14. module.exports = {
  15. mode: 'production',
  16. entry: {
  17. app: './app-ui/index.jsx'
  18. //, vendor: ['react', 'antd']
  19. },
  20. devtool: 'source-map',
  21. output: {
  22. path: path.join(__dirname, 'app', 'ui'),
  23. filename: '[name].js',
  24. sourceMapFilename: '[name].js.map'
  25. },
  26. resolve: {
  27. extensions: ['.js', '.jsx']
  28. },
  29. module: {
  30. rules: [
  31. {
  32. test: /\.jsx?$/,
  33. //exclude: [/node_modules/],
  34. use: ['babel-loader?sourceMap']
  35. },
  36. {
  37. test: /\.less$/,
  38. //exclude: [/node_modules/, /antd/],
  39. loader: ExtractTextPlugin.extract({
  40. fallback: 'style-loader',
  41. use: [
  42. 'css-loader?minimize&modules&sourceMap&localIdentName=[name]--[local]--[hash:base64:5]',
  43. {
  44. loader: 'less-loader?outputStyle=expanded',
  45. options: {
  46. javascriptEnabled: true,
  47. plugins: [
  48. new LESSPluginLists({advanced: true})
  49. ]
  50. }
  51. }
  52. ]
  53. })
  54. },
  55. {
  56. test: /\.css$/,
  57. loader: ExtractTextPlugin.extract({
  58. fallback: 'style-loader',
  59. use: 'css-loader?importLoaders=1&minimize&sourceMap'
  60. })
  61. },
  62. {
  63. test: /\.(eot|woff|woff2|ttf|svg|png|jpg)$/,
  64. use: 'url-loader?limit=30000&name=[name]-[hash].[ext]'
  65. }
  66. ],
  67. noParse: [/\bAgent\b/]
  68. },
  69. optimization: {
  70. minimizer: [
  71. new UglifyJsPlugin({
  72. cache: true,
  73. parallel: true,
  74. uglifyOptions: {
  75. compress: true,
  76. ecma: 6,
  77. mangle: true,
  78. output: {
  79. ascii_only: true
  80. }
  81. },
  82. sourceMap: true
  83. })
  84. ]
  85. },
  86. plugins: [
  87. new webpack.DefinePlugin({
  88. 'process.env': {
  89. NODE_ENV: JSON.stringify('production')
  90. }
  91. }),
  92. new ExtractTextPlugin({
  93. filename: '[name].css',
  94. allChunks: true
  95. }),
  96. new webpack.DllReferencePlugin({
  97. context: __dirname,
  98. manifest: require('../tmp/manifest.json')
  99. }),
  100. new webpack.IgnorePlugin(new RegExp('^(electron|fs|path)$')),
  101. new WebpackNotifierPlugin({
  102. title: 'SwitchHosts!',
  103. alwaysNotify: true,
  104. excludeWarnings: true
  105. }),
  106. new webpack.BannerPlugin(`SwitchHosts! [file] v${version}, ${moment().format('YYYY-MM-DD HH:mm:ss')}`)
  107. ]
  108. }