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.

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