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.

274 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 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. },
  174. plugins: [
  175. new VueLoaderPlugin(),
  176. new VuetifyLoaderPlugin(),
  177. new CopyWebpackPlugin([
  178. { from: 'client/static' },
  179. { from: './node_modules/prismjs/components', to: 'js/prism' }
  180. ], {}),
  181. new HtmlWebpackPlugin({
  182. template: 'dev/templates/master.pug',
  183. filename: '../server/views/master.pug',
  184. hash: false,
  185. inject: false,
  186. excludeChunks: ['setup', 'legacy']
  187. }),
  188. new HtmlWebpackPlugin({
  189. template: 'dev/templates/legacy.pug',
  190. filename: '../server/views/legacy/master.pug',
  191. hash: false,
  192. inject: false,
  193. excludeChunks: ['setup', 'app']
  194. }),
  195. new HtmlWebpackPlugin({
  196. template: 'dev/templates/setup.pug',
  197. filename: '../server/views/setup.pug',
  198. hash: false,
  199. inject: false,
  200. excludeChunks: ['app', 'legacy']
  201. }),
  202. new HtmlWebpackPugPlugin(),
  203. new SriWebpackPlugin({
  204. hashFuncNames: ['sha256', 'sha512'],
  205. enabled: false
  206. }),
  207. new WebpackBarPlugin({
  208. name: 'Client Assets'
  209. }),
  210. new webpack.DefinePlugin({
  211. 'process.env.NODE_ENV': JSON.stringify('development'),
  212. 'process.env.CURRENT_THEME': JSON.stringify(_.defaultTo(yargs.theme, 'default'))
  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. // Duplicates fixes:
  247. 'apollo-link': path.join(process.cwd(), 'node_modules/apollo-link'),
  248. 'apollo-utilities': path.join(process.cwd(), 'node_modules/apollo-utilities'),
  249. 'uc.micro': path.join(process.cwd(), 'node_modules/uc.micro')
  250. },
  251. extensions: [
  252. '.js',
  253. '.json',
  254. '.vue'
  255. ],
  256. modules: [
  257. 'node_modules'
  258. ]
  259. },
  260. node: {
  261. fs: 'empty'
  262. },
  263. stats: {
  264. children: false,
  265. entrypoints: false
  266. },
  267. target: 'web',
  268. watch: true
  269. }