webpack.config.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 LSSPluginLists = require('less-plugin-lists')
  12. const version = require('./app/version').version.join('.')
  13. module.exports = {
  14. entry: {
  15. app: './app-ui/index.jsx'
  16. //, vendor: ['react', 'antd']
  17. },
  18. devtool: 'source-map',
  19. output: {
  20. path: path.join(__dirname, 'app', 'ui')
  21. , filename: '[name].js'
  22. , sourceMapFilename: '[name].js.map'
  23. },
  24. resolve: {
  25. extensions: ['.js', '.jsx']
  26. },
  27. module: {
  28. rules: [
  29. {
  30. test: /\.jsx?$/,
  31. //exclude: [/node_modules/],
  32. use: ['babel-loader']
  33. }, {
  34. test: /\.less$/,
  35. //exclude: [/node_modules/, /antd/],
  36. loader: ExtractTextPlugin.extract({
  37. fallback: 'style-loader',
  38. use: [
  39. 'css-loader?minimize&modules&sourceMap&localIdentName=[name]--[local]--[hash:base64:5]',
  40. {
  41. loader: 'less-loader?outputStyle=expanded',
  42. options: {
  43. plugins: [
  44. new LSSPluginLists({advanced: true})
  45. ]
  46. }
  47. }
  48. ]
  49. })
  50. }, {
  51. test: /\.css$/,
  52. loader: ExtractTextPlugin.extract({
  53. fallback: 'style-loader',
  54. use: 'css-loader?importLoaders=1&minimize&sourceMap'
  55. })
  56. }, {
  57. test: /\.(eot|woff|woff2|ttf|svg|png|jpg)$/,
  58. use: 'url-loader?limit=30000&name=[name]-[hash].[ext]'
  59. }
  60. ]
  61. , noParse: [/\bAgent\b/]
  62. },
  63. plugins: [
  64. new webpack.DefinePlugin({
  65. 'process.env': {
  66. NODE_ENV: JSON.stringify('production')
  67. }
  68. })
  69. //, new webpack.optimize.CommonsChunkPlugin({name: 'vendor', filename: 'common.js'})
  70. , new webpack.optimize.UglifyJsPlugin({
  71. sourceMap: true,
  72. compress: {
  73. warnings: false
  74. , drop_console: false
  75. }
  76. , output: {
  77. comments: false
  78. }
  79. })
  80. , new ExtractTextPlugin({
  81. filename: '[name].css',
  82. allChunks: true
  83. })
  84. , new webpack.DllReferencePlugin({
  85. context: __dirname,
  86. manifest: require('./tmp/manifest.json')
  87. })
  88. , new webpack.IgnorePlugin(new RegExp('^(electron|fs|path)$'))
  89. , new WebpackNotifierPlugin({
  90. title: 'SwitchHosts!',
  91. alwaysNotify: true
  92. })
  93. , new webpack.BannerPlugin(`SwitchHosts! [file] v${version}, ${moment().format('YYYY-MM-DD HH:mm:ss')}`)
  94. ]
  95. }