resolveAppConfig.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. module.exports = (api, args, options) => {
  2. // respect inline entry
  3. if (args.entry && !options.pages) {
  4. api.configureWebpack(config => {
  5. config.entry = { app: api.resolve(args.entry) }
  6. })
  7. }
  8. const config = api.resolveChainableWebpackConfig()
  9. const targetDir = api.resolve(args.dest || options.outputDir)
  10. // respect inline build destination in copy plugin
  11. if (args.dest && config.plugins.has('copy')) {
  12. config.plugin('copy').tap(pluginArgs => {
  13. pluginArgs[0][0].to = targetDir
  14. return pluginArgs
  15. })
  16. }
  17. if (args.modern) {
  18. const ModernModePlugin = require('../../webpack/ModernModePlugin')
  19. if (!args.modernBuild) {
  20. // Inject plugin to extract build stats and write to disk
  21. config
  22. .plugin('modern-mode-legacy')
  23. .use(ModernModePlugin, [{
  24. targetDir,
  25. isModernBuild: false,
  26. unsafeInline: args['unsafe-inline']
  27. }])
  28. } else {
  29. // Inject plugin to read non-modern build stats and inject HTML
  30. config
  31. .plugin('modern-mode-modern')
  32. .use(ModernModePlugin, [{
  33. targetDir,
  34. isModernBuild: true,
  35. unsafeInline: args['unsafe-inline'],
  36. // as we may generate an addition file asset (if `no-unsafe-inline` specified)
  37. // we need to provide the correct directory for that file to place in
  38. jsDirectory: require('../../util/getAssetPath')(options, 'js')
  39. }])
  40. }
  41. }
  42. return api.resolveWebpackConfig(config)
  43. }