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.

276 lines
6.6 KiB

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