webpack.config.js 2.6KB

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