webpack.production.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. const webpack = require('webpack');
  2. const autoprefixer = require('autoprefixer');
  3. const path = require('path');
  4. const CleanWebpackPlugin = require('clean-webpack-plugin');
  5. const HtmlWebpackPlugin = require('html-webpack-plugin');
  6. const GLOBALS = {
  7. 'process.env': {NODE_ENV: '"production"',API_ROOT:'"/re"'}
  8. };
  9. let OUTPUT_PATH = 'dist/';
  10. let PUBLIC_PATH = '';
  11. if (process.env.EXTERNAL) {
  12. OUTPUT_PATH = 'build-external/';
  13. // Change this line to point to resources on an external host.
  14. PUBLIC_PATH = 'https://s3.amazonaws.com/static.weave.works/scope-ui/';
  15. }
  16. /**
  17. * This is the Webpack configuration file for production.
  18. */
  19. module.exports = {
  20. // fail on first error when building release
  21. bail: true,
  22. cache: {},
  23. entry: {
  24. app: './app/scripts/main',
  25. 'terminal-app': './app/scripts/terminal-main',
  26. // keep only some in here, to make vendors and app bundles roughly same size
  27. vendors: ['@babel/polyfill', 'classnames', 'immutable',
  28. 'react', 'react-dom', 'react-redux', 'redux', 'redux-thunk'
  29. ]
  30. },
  31. // See https://webpack.js.org/concepts/mode/#mode-production.
  32. mode: 'production',
  33. output: {
  34. filename: '[name]-[chunkhash].js',
  35. path: path.join(__dirname, OUTPUT_PATH),
  36. publicPath: PUBLIC_PATH,
  37. },
  38. plugins: [
  39. new CleanWebpackPlugin([OUTPUT_PATH]),
  40. new webpack.DefinePlugin(GLOBALS),
  41. new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
  42. new webpack.IgnorePlugin(/.*\.map$/, /xterm\/lib\/addons/),
  43. new HtmlWebpackPlugin({
  44. chunks: ['vendors', 'terminal-app'],
  45. filename: 'terminal.html',
  46. hash: true,
  47. template: 'app/html/index.html',
  48. }),
  49. new HtmlWebpackPlugin({
  50. chunks: ['vendors', 'app'],
  51. filename: 'index.html',
  52. hash: true,
  53. template: 'app/html/index.html',
  54. }),
  55. ],
  56. module: {
  57. // Webpack is opionated about how pkgs should be laid out:
  58. // https://github.com/webpack/webpack/issues/1617
  59. noParse: [/xterm\/dist\/xterm\.js/],
  60. rules: [
  61. {
  62. test: /\.js$/,
  63. exclude: /node_modules|vendor/,
  64. // loader: 'eslint-loader',
  65. use:[
  66. // {loader:"eslint-loader"},
  67. {
  68. loader:"babel-loader",
  69. options:{//options、query不能和loader数组一起使用
  70. cacheDirectory:true//利用缓存,提高性能,babel is slow
  71. },
  72. }
  73. ],
  74. enforce: 'pre',
  75. // options: {
  76. // failOnError: true
  77. // }
  78. },
  79. {
  80. test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
  81. loader: 'url-loader',
  82. options: {
  83. limit: 10000,
  84. minetype: 'application/font-woff',
  85. }
  86. },
  87. {
  88. test: /\.(ttf|eot|svg|ico)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
  89. loader: 'file-loader'
  90. },
  91. {
  92. test: /\.ico$/,
  93. loader: 'file-loader',
  94. options: {
  95. name: '[name].[ext]'
  96. }
  97. },
  98. {
  99. test: /\.jsx?$/,
  100. exclude: /node_modules|vendor/,
  101. loader: 'babel-loader'
  102. },
  103. {
  104. test: /\.(css|less)$/,
  105. use: [
  106. { loader: 'style-loader' },
  107. { loader: 'css-loader' },
  108. { loader: 'less-loader' },
  109. {
  110. loader: 'postcss-loader',
  111. options: {
  112. plugins: [
  113. autoprefixer({
  114. browsers: ['last 2 versions']
  115. })
  116. ]
  117. }
  118. },
  119. ],
  120. }
  121. ]
  122. },
  123. resolve: {
  124. extensions: ['.js', '.jsx']
  125. },
  126. };