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.

278 lines
6.9 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: /\.(woff2|woff|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
  161. use: [{
  162. loader: 'file-loader',
  163. options: {
  164. name: '[name].[ext]',
  165. outputPath: 'fonts/'
  166. }
  167. }]
  168. },
  169. {
  170. loader: 'webpack-modernizr-loader',
  171. test: /\.modernizrrc\.js$/
  172. }
  173. ]
  174. },
  175. plugins: [
  176. new VueLoaderPlugin(),
  177. new VuetifyLoaderPlugin(),
  178. new MomentTimezoneDataPlugin({
  179. startYear: 2017,
  180. endYear: (new Date().getFullYear()) + 5
  181. }),
  182. new CopyWebpackPlugin({
  183. patterns: [
  184. { from: 'client/static' },
  185. { from: './node_modules/prismjs/components', to: 'js/prism' }
  186. ]
  187. }),
  188. new HtmlWebpackPlugin({
  189. template: 'dev/templates/master.pug',
  190. filename: '../server/views/master.pug',
  191. hash: false,
  192. inject: false,
  193. excludeChunks: ['setup', 'legacy']
  194. }),
  195. new HtmlWebpackPlugin({
  196. template: 'dev/templates/legacy.pug',
  197. filename: '../server/views/legacy/master.pug',
  198. hash: false,
  199. inject: false,
  200. excludeChunks: ['setup', 'app']
  201. }),
  202. new HtmlWebpackPlugin({
  203. template: 'dev/templates/setup.pug',
  204. filename: '../server/views/setup.pug',
  205. hash: false,
  206. inject: false,
  207. excludeChunks: ['app', 'legacy']
  208. }),
  209. new HtmlWebpackPugPlugin(),
  210. new WebpackBarPlugin({
  211. name: 'Client Assets'
  212. }),
  213. new webpack.DefinePlugin({
  214. 'process.env.NODE_ENV': JSON.stringify('development'),
  215. 'process.env.CURRENT_THEME': JSON.stringify(_.defaultTo(yargs.theme, 'default'))
  216. }),
  217. new WriteFilePlugin(),
  218. new webpack.HotModuleReplacementPlugin(),
  219. new webpack.WatchIgnorePlugin([
  220. /node_modules/
  221. ])
  222. ],
  223. optimization: {
  224. namedModules: true,
  225. namedChunks: true,
  226. splitChunks: {
  227. cacheGroups: {
  228. default: {
  229. minChunks: 2,
  230. priority: -20,
  231. reuseExistingChunk: true
  232. },
  233. vendor: {
  234. test: /[\\/]node_modules[\\/]/,
  235. minChunks: 2,
  236. priority: -10
  237. }
  238. }
  239. },
  240. runtimeChunk: 'single'
  241. },
  242. resolve: {
  243. mainFields: ['browser', 'main', 'module'],
  244. symlinks: true,
  245. alias: {
  246. '@': path.join(process.cwd(), 'client'),
  247. 'vue$': 'vue/dist/vue.esm.js',
  248. 'gql': path.join(process.cwd(), 'client/graph'),
  249. // Duplicates fixes:
  250. 'apollo-link': path.join(process.cwd(), 'node_modules/apollo-link'),
  251. 'apollo-utilities': path.join(process.cwd(), 'node_modules/apollo-utilities'),
  252. 'uc.micro': path.join(process.cwd(), 'node_modules/uc.micro'),
  253. 'modernizr$': path.resolve(process.cwd(), 'client/.modernizrrc.js')
  254. },
  255. extensions: [
  256. '.js',
  257. '.json',
  258. '.vue'
  259. ],
  260. modules: [
  261. 'node_modules'
  262. ]
  263. },
  264. node: {
  265. fs: 'empty'
  266. },
  267. stats: {
  268. children: false,
  269. entrypoints: false
  270. },
  271. target: 'web',
  272. watch: true
  273. }