Advertisement
Guest User

Untitled

a guest
Jan 29th, 2023
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.16 KB | None | 0 0
  1. const { join } = require('path')
  2. const Encore = require('@symfony/webpack-encore')
  3.  
  4. /*
  5. |--------------------------------------------------------------------------
  6. | Encore runtime environment
  7. |--------------------------------------------------------------------------
  8. */
  9. if (!Encore.isRuntimeEnvironmentConfigured()) {
  10. Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev')
  11. }
  12.  
  13. /*
  14. |--------------------------------------------------------------------------
  15. | Output path
  16. |--------------------------------------------------------------------------
  17. |
  18. | The output path for writing the compiled files. It should always
  19. | be inside the public directory, so that AdonisJS can serve it.
  20. |
  21. */
  22. Encore.setOutputPath('./public/assets')
  23.  
  24. /*
  25. |--------------------------------------------------------------------------
  26. | Public URI
  27. |--------------------------------------------------------------------------
  28. |
  29. | The public URI to access the static files. It should always be
  30. | relative from the "public" directory.
  31. |
  32. */
  33. Encore.setPublicPath('/assets')
  34.  
  35. /*
  36. |--------------------------------------------------------------------------
  37. | Entrypoints
  38. |--------------------------------------------------------------------------
  39. |
  40. | Entrypoints are script files that boots your frontend application. Ideally
  41. | a single entrypoint is used by majority of applications. However, feel
  42. | free to add more (if required).
  43. |
  44. | Also, make sure to read the docs on "Assets bundler" to learn more about
  45. | entrypoints.
  46. |
  47. */
  48. Encore.addEntry('app', './resources/js/app.tsx')
  49.  
  50. /*
  51. |--------------------------------------------------------------------------
  52. | Copy assets
  53. |--------------------------------------------------------------------------
  54. |
  55. | Since the edge templates are not part of the Webpack compile lifecycle, any
  56. | images referenced by it will not be processed by Webpack automatically. Hence
  57. | we must copy them manually.
  58. |
  59. */
  60. Encore.copyFiles({
  61. from: './resources/image',
  62. to: 'image/[path][name].[hash:8].[ext]',
  63. })
  64.  
  65. Encore.copyFiles({
  66. from: './resources/locale',
  67. to: 'locale/[path][name].[hash:8].[ext]',
  68. })
  69.  
  70. /*
  71. |--------------------------------------------------------------------------
  72. | Split shared code
  73. |--------------------------------------------------------------------------
  74. |
  75. | Instead of bundling duplicate code in all the bundles, generate a separate
  76. | bundle for the shared code.
  77. |
  78. | https://symfony.com/doc/current/frontend/encore/split-chunks.html
  79. | https://webpack.js.org/plugins/split-chunks-plugin/
  80. |
  81. */
  82. // Encore.splitEntryChunks()
  83.  
  84. /*
  85. |--------------------------------------------------------------------------
  86. | Isolated entrypoints
  87. |--------------------------------------------------------------------------
  88. |
  89. | Treat each entry point and its dependencies as its own isolated module.
  90. |
  91. */
  92. Encore.disableSingleRuntimeChunk()
  93.  
  94. /*
  95. |--------------------------------------------------------------------------
  96. | Cleanup output folder
  97. |--------------------------------------------------------------------------
  98. |
  99. | It is always nice to cleanup the build output before creating a build. It
  100. | will ensure that all unused files from the previous build are removed.
  101. |
  102. */
  103. Encore.cleanupOutputBeforeBuild()
  104.  
  105. /*
  106. |--------------------------------------------------------------------------
  107. | Source maps
  108. |--------------------------------------------------------------------------
  109. |
  110. | Enable source maps in production
  111. |
  112. */
  113. Encore.enableSourceMaps(!Encore.isProduction())
  114.  
  115. /*
  116. |--------------------------------------------------------------------------
  117. | Assets versioning
  118. |--------------------------------------------------------------------------
  119. |
  120. | Enable assets versioning to leverage lifetime browser and CDN cache
  121. |
  122. */
  123. Encore.enableVersioning(Encore.isProduction())
  124.  
  125. /*
  126. |--------------------------------------------------------------------------
  127. | Configure dev server
  128. |--------------------------------------------------------------------------
  129. |
  130. | Here we configure the dev server to enable live reloading for edge templates.
  131. | Remember edge templates are not processed by Webpack and hence we need
  132. | to watch them explicitly and livereload the browser.
  133. |
  134. */
  135. Encore.configureDevServerOptions((options) => {
  136. /**
  137. * Normalize "options.static" property to an array
  138. */
  139. if (!options.static) {
  140. options.static = []
  141. } else if (!Array.isArray(options.static)) {
  142. options.static = [options.static]
  143. }
  144.  
  145. /**
  146. * Enable live reload and add views directory
  147. */
  148. options.liveReload = true
  149. options.static.push({
  150. directory: join(__dirname, './resources/views'),
  151. watch: true,
  152. })
  153. })
  154.  
  155. /*
  156. |--------------------------------------------------------------------------
  157. | CSS precompilers support
  158. |--------------------------------------------------------------------------
  159. |
  160. | Uncomment one of the following lines of code to enable support for your
  161. | favorite CSS precompiler
  162. |
  163. */
  164. // Encore.enableSassLoader()
  165. // Encore.enableLessLoader()
  166. // Encore.enableStylusLoader()
  167.  
  168. /*
  169. |--------------------------------------------------------------------------
  170. | CSS loaders
  171. |--------------------------------------------------------------------------
  172. |
  173. | Uncomment one of the following line of code to enable support for
  174. | PostCSS or CSS.
  175. |
  176. */
  177. Encore.enablePostCssLoader()
  178. //Encore.configureCssLoader(() => {})
  179.  
  180. Encore.enableTypeScriptLoader()
  181. Encore.enableReactPreset()
  182.  
  183. /*
  184. |--------------------------------------------------------------------------
  185. | Configure logging
  186. |--------------------------------------------------------------------------
  187. |
  188. | To keep the terminal clean from unnecessary info statements , we only
  189. | log warnings and errors. If you want all the logs, you can change
  190. | the level to "info".
  191. |
  192. */
  193. const config = Encore.getWebpackConfig()
  194. config.infrastructureLogging = {
  195. level: 'warn',
  196. }
  197. config.stats = 'errors-warnings'
  198.  
  199. /*
  200. |--------------------------------------------------------------------------
  201. | Export config
  202. |--------------------------------------------------------------------------
  203. |
  204. | Export config for webpack to do its job
  205. |
  206. */
  207. module.exports = config
  208.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement