Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. const os = require('os');
  2. const path = require('path');
  3. const webpack = require('webpack');
  4. const HtmlWebpackPlugin = require('html-webpack-plugin');
  5. const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin');
  6. const HappyPack = require('happypack');
  7. const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
  8. const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin');
  9. const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
  10. const autoprefixer = require('autoprefixer');
  11.  
  12. const publicPath = path.resolve(__dirname, 'public');
  13. const srcPath = path.resolve(__dirname, 'src');
  14. const libPath = path.resolve(__dirname, 'lib');
  15. const distPath = path.resolve(__dirname, 'dist');
  16. const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
  17. const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
  18. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  19. const nodeExternals = require('webpack-node-externals');
  20. const CleanWebpackPlugin = require('clean-webpack-plugin')
  21.  
  22. module.exports = (app = 'index') => {
  23. return {
  24. mode: 'development',
  25. devtool: 'cheap-module-eval-source-map',
  26. entry: ['babel-polyfill', path.resolve(__dirname, 'app')],
  27. output: {
  28. path: __dirname,
  29. filename: 'app.compiled.js',
  30. libraryTarget: 'commonjs2',
  31. publicPath: '/'
  32. },
  33. target: 'node',
  34. node: {
  35. __dirname: true,
  36. __filename: true
  37. },
  38. externals: nodeExternals({
  39. // load non-javascript files with extensions, presumably via loaders
  40. whitelist: [/\.(?!(?:jsx?|json)$).{1,5}$/i]
  41. }),
  42. module: {
  43. rules: [
  44. {
  45. test: /\.(js|jsx)$/,
  46. exclude: /(node_modules)/,
  47. use: ['happypack/loader?id=jsx']
  48. },
  49. {
  50. test: /\.(css|scss)$/,
  51. use: ['ignore-loader']
  52. },
  53. {
  54. test: /\.(png|jpg|jpeg|gif|mp4|ogg|svg|woff|woff2|ttf|eot)$/,
  55. use: {
  56. loader: 'file-loader',
  57. options: {
  58. context: publicPath,
  59. name: '[path][name].[ext]'
  60. }
  61. }
  62. }
  63. ]
  64. },
  65. optimization: {
  66. minimize: false,
  67. splitChunks: {
  68. chunks: 'all',
  69. name: false,
  70. minChunks: 2,
  71. cacheGroups: {
  72. default: false,
  73. vendors: false,
  74. common: {
  75. test: /\.jsx?$/,
  76. name: 'common',
  77. reuseExistingChunk: true
  78. }
  79. }
  80. }
  81. },
  82. resolve: {
  83. extensions: ['.js', '.jsx', '.css', '.scss'],
  84. modules: [srcPath, 'node_modules'],
  85. alias: {
  86. '@img': path.resolve(publicPath, 'img'),
  87. global: path.resolve(publicPath, 'sass/_global.scss')
  88. }
  89. },
  90. performance: {
  91. hints: false
  92. },
  93. plugins: [
  94. new HardSourceWebpackPlugin(),
  95. new webpack.ProvidePlugin({
  96. 'window.Quill': 'quill'
  97. }),
  98. new HappyPack({
  99. id: 'jsx',
  100. threadPool: happyThreadPool,
  101. loaders: [
  102. {
  103. loader: 'babel-loader',
  104. options: {
  105. cacheDirectory: true,
  106. presets: ['env', 'react'],
  107. plugins: ['transform-runtime', 'transform-object-rest-spread']
  108. }
  109. }
  110. ]
  111. })
  112. //,new webpack.HotModuleReplacementPlugin()
  113. ]
  114. };
  115. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement