Guest User

Untitled

a guest
Dec 14th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. const path = require('path')
  2. const webpack = require('webpack')
  3. const HtmlWebpackPlugin = require('html-webpack-plugin')
  4. const ExtractTextPlugin = require('extract-text-webpack-plugin')
  5. const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin')
  6. const CopyWebpackPlugin = require('copy-webpack-plugin')
  7. const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
  8. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  9. const MinifyPlugin = require("babel-minify-webpack-plugin");
  10.  
  11. const CONFIG = require('./config')
  12.  
  13. module.exports = function (env) {
  14. return {
  15. devtool: 'cheap-module-source-map',
  16. entry: {
  17. app: CONFIG.APP_PATH + CONFIG.CLIENT_ENTRY_FILE,
  18. },
  19. output: {
  20. path: path.resolve(CONFIG.CLIENT_OUTPUT_PATH),
  21. chunkFilename: '[name].bundle-[chunkhash].js',
  22. filename: 'bundle-[chunkhash].js',
  23. },
  24. resolve: {
  25. extensions: ['.js'],
  26. },
  27. stats: {
  28. reasons: true,
  29. },
  30. devServer: CONFIG.WEBPACK_DEV_SERVER_CONFIG,
  31. plugins: [
  32. new webpack.DefinePlugin({
  33. 'process.env.NODE_ENV': JSON.stringify('production'),
  34. }),
  35.  
  36. new HtmlWebpackPlugin(Object.assign({}, CONFIG.HtmlWebpackPlugin, {
  37. minify: {
  38. removeComments: true,
  39. collapseWhitespace: true,
  40. removeRedundantAttributes: true,
  41. useShortDoctype: true,
  42. removeEmptyAttributes: true,
  43. keepClosingSlash: true,
  44. minifyJS: true,
  45. minifyCSS: true,
  46. minifyURLs: true,
  47. },
  48. inject: true,
  49. })),
  50.  
  51. new ExtractTextPlugin('styles.[chunkhash].css'),
  52.  
  53. // eradicates unused locales
  54. new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /nb/),
  55.  
  56. new MinifyPlugin(),
  57.  
  58. // new SWPrecacheWebpackPlugin({
  59. // cacheId: 'kaptura-v1',
  60. // filename: 'service-worker.js',
  61. // maximumFileSizeToCacheInBytes: 4194304,
  62. // minify: true,
  63. // staticFileGlobs: [
  64. // 'public/**/*.css',
  65. // 'public/**/*.js',
  66. // 'public/**/*.html',
  67. // ],
  68. // stripPrefix: 'public/',
  69. // }),
  70.  
  71.  
  72. new webpack.optimize.CommonsChunkPlugin({
  73. name: 'vendor',
  74. // filename: 'commons-[chunkhash].js',
  75.  
  76. // create a additional async chunk for the common modules
  77. // which is loaded in parallel to the requested chunks
  78. async: true,
  79.  
  80. minChunks: function (module) {
  81. // this assumes your vendor imports exist in the node_modules directory
  82. return module.context && module.context.indexOf("node_modules") !== -1;
  83. }
  84. }),
  85.  
  86. new CopyWebpackPlugin([{
  87. from: 'src/manifest.json',
  88. to: '',
  89. },
  90. {
  91. from: 'resources/favicon.ico',
  92. to: '',
  93. },
  94. {
  95. context: 'resources',
  96. from: '*.png',
  97. },
  98. ]),
  99.  
  100. // TODO: works but generated manifest needs config
  101. // new FaviconsWebpackPlugin('./resources/logo.png'),
  102.  
  103.  
  104. new BundleAnalyzerPlugin(),
  105. ],
  106. module: {
  107. rules: [{
  108. test: /\.js$/,
  109. use: 'babel-loader',
  110. include: [
  111. path.resolve('src/web'),
  112. ],
  113. exclude: ['.spec.'],
  114. },
  115. {
  116. test: /\.scss$/,
  117. use: ExtractTextPlugin.extract({
  118. fallback: "style-loader",
  119. use: ['css-loader', 'sass-loader']
  120. })
  121. },
  122. {
  123. test: /\.css$/,
  124. use: ExtractTextPlugin.extract({
  125. fallback: 'style-loader',
  126. use: 'css-loader'
  127. })
  128. },
  129.  
  130. {
  131. test: /\.(gif|png|jpe?g|svg)$/i,
  132. use: [
  133. 'file-loader?hash=sha512&digest=hex&name=[hash].[ext]',
  134. {
  135. loader: 'image-webpack-loader',
  136. query: {
  137. progressive: true,
  138. optimizationLevel: 7,
  139. interlaced: false,
  140. pngquant: {
  141. quality: '65-90',
  142. speed: 4
  143. }
  144. }
  145. }
  146. ]
  147. },
  148. ]
  149. }
  150. }
  151. }
Add Comment
Please, Sign In to add comment