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.

284 lines
7.0 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. sassOptions: {
  84. fiber: false
  85. }
  86. }
  87. }
  88. ]
  89. },
  90. {
  91. test: /\.scss$/,
  92. use: [
  93. {
  94. loader: 'cache-loader',
  95. options: {
  96. cacheDirectory: cacheDir
  97. }
  98. },
  99. 'style-loader',
  100. 'css-loader',
  101. 'postcss-loader',
  102. {
  103. loader: 'sass-loader',
  104. options: {
  105. implementation: require('sass'),
  106. sourceMap: false,
  107. sassOptions: {
  108. fiber: false
  109. }
  110. }
  111. },
  112. {
  113. loader: 'sass-resources-loader',
  114. options: {
  115. resources: path.join(process.cwd(), '/client/scss/global.scss')
  116. }
  117. }
  118. ]
  119. },
  120. {
  121. test: /\.vue$/,
  122. loader: 'vue-loader'
  123. },
  124. {
  125. test: /\.pug$/,
  126. exclude: [
  127. path.join(process.cwd(), 'dev')
  128. ],
  129. loader: 'pug-plain-loader'
  130. },
  131. {
  132. test: /\.(png|jpg|gif)$/,
  133. use: [
  134. {
  135. loader: 'url-loader',
  136. options: {
  137. limit: 8192
  138. }
  139. }
  140. ]
  141. },
  142. {
  143. test: /\.svg$/,
  144. exclude: [
  145. path.join(process.cwd(), 'node_modules/grapesjs')
  146. ],
  147. use: [
  148. {
  149. loader: 'file-loader',
  150. options: {
  151. name: '[name].[ext]',
  152. outputPath: 'svg/'
  153. }
  154. }
  155. ]
  156. },
  157. {
  158. test: /\.(graphql|gql)$/,
  159. exclude: /node_modules/,
  160. use: [
  161. { loader: 'graphql-persisted-document-loader' },
  162. { loader: 'graphql-tag/loader' }
  163. ]
  164. },
  165. {
  166. test: /\.(woff2|woff|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
  167. use: [{
  168. loader: 'file-loader',
  169. options: {
  170. name: '[name].[ext]',
  171. outputPath: 'fonts/'
  172. }
  173. }]
  174. },
  175. {
  176. loader: 'webpack-modernizr-loader',
  177. test: /\.modernizrrc\.js$/
  178. }
  179. ]
  180. },
  181. plugins: [
  182. new VueLoaderPlugin(),
  183. new VuetifyLoaderPlugin(),
  184. new MomentTimezoneDataPlugin({
  185. startYear: 2017,
  186. endYear: (new Date().getFullYear()) + 5
  187. }),
  188. new CopyWebpackPlugin({
  189. patterns: [
  190. { from: 'client/static' },
  191. { from: './node_modules/prismjs/components', to: 'js/prism' }
  192. ]
  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 WebpackBarPlugin({
  217. name: 'Client Assets'
  218. }),
  219. new webpack.DefinePlugin({
  220. 'process.env.NODE_ENV': JSON.stringify('development'),
  221. 'process.env.CURRENT_THEME': JSON.stringify(_.defaultTo(yargs.theme, 'default'))
  222. }),
  223. new WriteFilePlugin(),
  224. new webpack.HotModuleReplacementPlugin(),
  225. new webpack.WatchIgnorePlugin([
  226. /node_modules/
  227. ])
  228. ],
  229. optimization: {
  230. namedModules: true,
  231. namedChunks: true,
  232. splitChunks: {
  233. cacheGroups: {
  234. default: {
  235. minChunks: 2,
  236. priority: -20,
  237. reuseExistingChunk: true
  238. },
  239. vendor: {
  240. test: /[\\/]node_modules[\\/]/,
  241. minChunks: 2,
  242. priority: -10
  243. }
  244. }
  245. },
  246. runtimeChunk: 'single'
  247. },
  248. resolve: {
  249. mainFields: ['browser', 'main', 'module'],
  250. symlinks: true,
  251. alias: {
  252. '@': path.join(process.cwd(), 'client'),
  253. 'vue$': 'vue/dist/vue.esm.js',
  254. 'gql': path.join(process.cwd(), 'client/graph'),
  255. // Duplicates fixes:
  256. 'apollo-link': path.join(process.cwd(), 'node_modules/apollo-link'),
  257. 'apollo-utilities': path.join(process.cwd(), 'node_modules/apollo-utilities'),
  258. 'uc.micro': path.join(process.cwd(), 'node_modules/uc.micro'),
  259. 'modernizr$': path.resolve(process.cwd(), 'client/.modernizrrc.js')
  260. },
  261. extensions: [
  262. '.js',
  263. '.json',
  264. '.vue'
  265. ],
  266. modules: [
  267. 'node_modules'
  268. ]
  269. },
  270. node: {
  271. fs: 'empty'
  272. },
  273. stats: {
  274. children: false,
  275. entrypoints: false
  276. },
  277. target: 'web',
  278. watch: true
  279. }