webpack.config.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. const webpack = require('webpack')
  2. const path = require('path')
  3. const isProduction = process.env.NODE_ENV === 'production'
  4. console.log('isProduction : ', isProduction)
  5. module.exports = {
  6. entry: isProduction ? './src/index.js' : './src/index.dev.js',
  7. output: {
  8. path: path.resolve(__dirname, 'dist'),
  9. filename: isProduction ? 'pageHtml.plugin.js' : 'pageHtml.plugin.dev.js',
  10. pathinfo: !isProduction,
  11. library: isProduction ? 'tracim_lib' : undefined,
  12. libraryTarget: isProduction ? 'umd' : undefined,
  13. umdNamedDefine: isProduction
  14. },
  15. externals: isProduction
  16. ? {
  17. react: {commonjs: 'react', commonjs2: 'react', amd: 'react', root: '_'},
  18. 'react-dom': {commonjs: 'react-dom', commonjs2: 'react-dom', amd: 'react-dom', root: '_'},
  19. classnames: {commonjs: 'classnames', commonjs2: 'classnames', amd: 'classnames', root: '_'},
  20. 'prop-types': {commonjs: 'prop-types', commonjs2: 'prop-types', amd: 'prop-types', root: '_'},
  21. tracim_lib: {commonjs: 'tracim_lib', commonjs2: 'tracim_lib', amd: 'tracim_lib', root: '_'}
  22. }
  23. : {},
  24. devServer: {
  25. contentBase: path.join(__dirname, 'dist/'),
  26. port: 8071,
  27. hot: true,
  28. noInfo: true,
  29. overlay: {
  30. warnings: false,
  31. errors: true
  32. },
  33. historyApiFallback: true
  34. // headers: {
  35. // 'Access-Control-Allow-Origin': '*'
  36. // }
  37. },
  38. devtool: isProduction ? false : 'cheap-module-source-map',
  39. module: {
  40. rules: [{
  41. test: /\.jsx?$/,
  42. enforce: 'pre',
  43. use: 'standard-loader',
  44. exclude: [/node_modules/]
  45. }, {
  46. test: [/\.js$/, /\.jsx$/],
  47. loader: 'babel-loader',
  48. options: {
  49. presets: ['env', 'react'],
  50. plugins: ['transform-object-rest-spread', 'transform-class-properties', 'transform-object-assign']
  51. },
  52. exclude: [/node_modules/]
  53. }, {
  54. test: /\.css$/,
  55. use: ['style-loader', 'css-loader']
  56. }, {
  57. test: /\.styl$/,
  58. use: ['style-loader', 'css-loader', 'stylus-loader']
  59. }, {
  60. test: /\.(jpg|png|svg)$/,
  61. loader: 'url-loader',
  62. options: {
  63. limit: 25000
  64. }
  65. }]
  66. },
  67. resolve: {
  68. extensions: ['.js', '.jsx']
  69. },
  70. plugins:[
  71. ...[], // generic plugins always present
  72. ...(isProduction
  73. ? [ // production specific plugins
  74. new webpack.DefinePlugin({
  75. 'process.env': { 'NODE_ENV': JSON.stringify('production') }
  76. }),
  77. new webpack.optimize.UglifyJsPlugin({
  78. compress: { warnings: false }
  79. })
  80. ]
  81. : [] // development specific plugins
  82. )
  83. ]
  84. }