validateWebpackConfig.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. module.exports = function validateWebpackConfig (
  2. webpackConfig,
  3. api,
  4. options,
  5. target = 'app'
  6. ) {
  7. const singleConfig = Array.isArray(webpackConfig)
  8. ? webpackConfig[0]
  9. : webpackConfig
  10. const actualTargetDir = singleConfig.output.path
  11. if (actualTargetDir !== api.resolve(options.outputDir)) {
  12. // user directly modifies output.path in configureWebpack or chainWebpack.
  13. // this is not supported because there's no way for us to give copy
  14. // plugin the correct value this way.
  15. throw new Error(
  16. `\n\nConfiguration Error: ` +
  17. `Avoid modifying webpack output.path directly. ` +
  18. `Use the "outputDir" option instead.\n`
  19. )
  20. }
  21. if (actualTargetDir === api.service.context) {
  22. throw new Error(
  23. `\n\nConfiguration Error: ` +
  24. `Do not set output directory to project root.\n`
  25. )
  26. }
  27. if (target === 'app' && singleConfig.output.publicPath !== options.publicPath) {
  28. throw new Error(
  29. `\n\nConfiguration Error: ` +
  30. `Avoid modifying webpack output.publicPath directly. ` +
  31. `Use the "publicPath" option instead.\n`
  32. )
  33. }
  34. }