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.8 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 MomentTimezoneDataPlugin = require('moment-timezone-data-webpack-plugin')
  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: '/_assets/',
  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. },
  174. plugins: [
  175. new VueLoaderPlugin(),
  176. new VuetifyLoaderPlugin(),
  177. new MomentTimezoneDataPlugin({
  178. startYear: 2017,
  179. endYear: (new Date().getFullYear()) + 5
  180. }),
  181. new CopyWebpackPlugin({
  182. patterns: [
  183. { from: 'client/static' },
  184. { from: './node_modules/prismjs/components', to: 'js/prism' }
  185. ]
  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', 'legacy']
  193. }),
  194. new HtmlWebpackPlugin({
  195. template: 'dev/templates/legacy.pug',
  196. filename: '../server/views/legacy/master.pug',
  197. hash: false,
  198. inject: false,
  199. excludeChunks: ['setup', 'app']
  200. }),
  201. new HtmlWebpackPlugin({
  202. template: 'dev/templates/setup.pug',
  203. filename: '../server/views/setup.pug',
  204. hash: false,
  205. inject: false,
  206. excludeChunks: ['app', 'legacy']
  207. }),
  208. new HtmlWebpackPugPlugin(),
  209. new WebpackBarPlugin({
  210. name: 'Client Assets'
  211. }),
  212. new webpack.DefinePlugin({
  213. 'process.env.NODE_ENV': JSON.stringify('development'),
  214. 'process.env.CURRENT_THEME': JSON.stringify(_.defaultTo(yargs.theme, 'default'))
  215. }),
  216. new WriteFilePlugin(),
  217. new webpack.HotModuleReplacementPlugin(),
  218. new webpack.WatchIgnorePlugin([
  219. /node_modules/
  220. ])
  221. ],
  222. optimization: {
  223. namedModules: true,
  224. namedChunks: true,
  225. splitChunks: {
  226. cacheGroups: {
  227. default: {
  228. minChunks: 2,
  229. priority: -20,
  230. reuseExistingChunk: true
  231. },
  232. vendor: {
  233. test: /[\\/]node_modules[\\/]/,
  234. minChunks: 2,
  235. priority: -10
  236. }
  237. }
  238. },
  239. runtimeChunk: 'single'
  240. },
  241. resolve: {
  242. mainFields: ['browser', 'main', 'module'],
  243. symlinks: true,
  244. alias: {
  245. '@': path.join(process.cwd(), 'client'),
  246. 'vue$': 'vue/dist/vue.esm.js',
  247. 'gql': path.join(process.cwd(), 'client/graph'),
  248. // Duplicates fixes:
  249. 'apollo-link': path.join(process.cwd(), 'node_modules/apollo-link'),
  250. 'apollo-utilities': path.join(process.cwd(), 'node_modules/apollo-utilities'),
  251. 'uc.micro': path.join(process.cwd(), 'node_modules/uc.micro')
  252. },
  253. extensions: [
  254. '.js',
  255. '.json',
  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. }