You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

254 lines
5.9 KiB

  1. const webpack = require('webpack')
  2. const path = require('path')
  3. const fs = require('fs-extra')
  4. const CopyWebpackPlugin = require('copy-webpack-plugin')
  5. const HtmlWebpackPlugin = require('html-webpack-plugin')
  6. const HtmlWebpackPugPlugin = require('html-webpack-pug-plugin')
  7. const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin')
  8. const WriteFilePlugin = require('write-file-webpack-plugin')
  9. const babelConfig = fs.readJsonSync(path.join(process.cwd(), '.babelrc'))
  10. const cacheDir = '.webpack-cache/cache'
  11. const babelDir = path.join(process.cwd(), '.webpack-cache/babel')
  12. process.noDeprecation = true
  13. module.exports = {
  14. mode: 'development',
  15. entry: {
  16. client: ['./client/index.js', 'webpack-hot-middleware/client']
  17. },
  18. output: {
  19. path: path.join(process.cwd(), 'assets'),
  20. publicPath: '/',
  21. filename: 'js/[name].js',
  22. chunkFilename: 'js/[name].js',
  23. globalObject: 'this',
  24. pathinfo: true
  25. },
  26. module: {
  27. rules: [
  28. {
  29. test: /\.js$/,
  30. exclude: /node_modules/,
  31. use: [
  32. {
  33. loader: 'cache-loader',
  34. options: {
  35. cacheDirectory: cacheDir
  36. }
  37. },
  38. {
  39. loader: 'babel-loader',
  40. options: {
  41. ...babelConfig,
  42. cacheDirectory: babelDir
  43. }
  44. }
  45. ]
  46. },
  47. {
  48. test: /\.css$/,
  49. use: [
  50. 'style-loader',
  51. 'css-loader',
  52. 'postcss-loader'
  53. ]
  54. },
  55. {
  56. test: /\.scss$/,
  57. use: [
  58. {
  59. loader: 'cache-loader',
  60. options: {
  61. cacheDirectory: cacheDir
  62. }
  63. },
  64. 'style-loader',
  65. 'css-loader',
  66. 'postcss-loader',
  67. {
  68. loader: 'sass-loader',
  69. options: {
  70. sourceMap: false
  71. }
  72. }
  73. ]
  74. },
  75. {
  76. test: /\.styl$/,
  77. use: [
  78. 'style-loader',
  79. 'css-loader',
  80. 'postcss-loader',
  81. 'stylus-loader'
  82. ]
  83. },
  84. {
  85. test: /\.vue$/,
  86. loader: 'vue-loader',
  87. options: {
  88. loaders: {
  89. scss: [
  90. 'vue-style-loader',
  91. 'css-loader',
  92. 'postcss-loader',
  93. {
  94. loader: 'sass-loader',
  95. options: {
  96. sourceMap: false
  97. }
  98. },
  99. {
  100. loader: 'sass-resources-loader',
  101. options: {
  102. resources: path.join(process.cwd(), '/client/scss/global.scss')
  103. }
  104. }
  105. ],
  106. js: [
  107. {
  108. loader: 'cache-loader',
  109. options: {
  110. cacheDirectory: cacheDir
  111. }
  112. },
  113. {
  114. loader: 'babel-loader',
  115. options: {
  116. babelrc: path.join(process.cwd(), '.babelrc'),
  117. cacheDirectory: babelDir
  118. }
  119. }
  120. ]
  121. }
  122. }
  123. },
  124. {
  125. test: /\.(png|jpg|gif)$/,
  126. use: [
  127. {
  128. loader: 'url-loader',
  129. options: {
  130. limit: 8192
  131. }
  132. }
  133. ]
  134. },
  135. {
  136. test: /\.svg$/,
  137. exclude: [
  138. path.join(process.cwd(), 'client/svg')
  139. ],
  140. use: [
  141. {
  142. loader: 'file-loader',
  143. options: {
  144. name: '[name].[ext]',
  145. outputPath: 'svg/'
  146. }
  147. }
  148. ]
  149. },
  150. {
  151. test: /\.svg$/,
  152. include: [
  153. path.join(process.cwd(), 'client/svg')
  154. ],
  155. use: [
  156. {
  157. loader: 'raw-loader'
  158. }
  159. ]
  160. },
  161. {
  162. test: /.jsx$/,
  163. loader: 'babel-loader',
  164. exclude: /node_modules/,
  165. options: {
  166. presets: ['es2015', 'react']
  167. }
  168. },
  169. {
  170. test: /\.flow$/,
  171. loader: 'ignore-loader'
  172. }
  173. ]
  174. },
  175. plugins: [
  176. new CopyWebpackPlugin([
  177. { from: 'client/static' },
  178. { from: './node_modules/graphql-voyager/dist/voyager.worker.js', to: 'js/' }
  179. ], {}),
  180. new HtmlWebpackPlugin({
  181. template: 'dev/templates/master.pug',
  182. filename: '../server/views/master.pug',
  183. hash: false,
  184. inject: 'head'
  185. }),
  186. new HtmlWebpackPugPlugin(),
  187. new SimpleProgressWebpackPlugin({
  188. format: 'compact'
  189. }),
  190. new webpack.DefinePlugin({
  191. 'process.env': { NODE_ENV: '"development"' },
  192. '__REACT_DEVTOOLS_GLOBAL_HOOK__': '({ isDisabled: true })'
  193. }),
  194. new WriteFilePlugin(),
  195. new webpack.HotModuleReplacementPlugin(),
  196. new webpack.WatchIgnorePlugin([
  197. /node_modules/
  198. ])
  199. ],
  200. optimization: {
  201. namedModules: true,
  202. namedChunks: true,
  203. splitChunks: {
  204. cacheGroups: {
  205. default: {
  206. minChunks: 2,
  207. priority: -20,
  208. reuseExistingChunk: true
  209. },
  210. vendor: {
  211. test: /[\\/]node_modules[\\/]/,
  212. minChunks: 2,
  213. priority: -10
  214. }
  215. }
  216. },
  217. runtimeChunk: 'single'
  218. },
  219. resolve: {
  220. mainFields: ['browser', 'main', 'module'],
  221. symlinks: true,
  222. alias: {
  223. '@': path.join(process.cwd(), 'client'),
  224. 'vue$': 'vue/dist/vue.esm.js',
  225. 'mdi': path.resolve(process.cwd(), 'node_modules/vue-material-design-icons'),
  226. // Duplicates fixes:
  227. 'apollo-link': path.join(process.cwd(), 'node_modules/apollo-link'),
  228. 'apollo-utilities': path.join(process.cwd(), 'node_modules/apollo-utilities'),
  229. 'uc.micro': path.join(process.cwd(), 'node_modules/uc.micro')
  230. },
  231. extensions: [
  232. '.js',
  233. '.json',
  234. '.jsx',
  235. '.vue'
  236. ],
  237. modules: [
  238. 'node_modules'
  239. ]
  240. },
  241. node: {
  242. fs: 'empty'
  243. },
  244. stats: {
  245. children: false,
  246. entrypoints: false
  247. },
  248. target: 'web',
  249. watch: true
  250. }