webpack.config.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const path = require("path"); // NodeJS builtin.
  2. module.exports = {
  3. entry: "./src/index.js",
  4. output: {
  5. filename: "bundle.js",
  6. path: path.join(__dirname, "build") // path must be absolute.
  7. },
  8. module: {
  9. rules: [
  10. // Loaders stream one file at a time before it is inserted into the
  11. // depencency graph.
  12. {
  13. // When a file name matches this expression...
  14. test: /\.js$/,
  15. // ...use that loader on it.
  16. use: "babel-loader"
  17. },
  18. {
  19. test: /\.scss$/,
  20. use: [
  21. // Apply down to top (right to left), like wrapped function calls.
  22. "style-loader", // Apply third: insert script tag for browser use.
  23. "css-loader", // Apply second: convert CSS to JS.
  24. "sass-loader" // Apply first: compile SASS to CSS.
  25. ]
  26. },
  27. {
  28. // Even for files requested by the CSS loader, which marks them as dependencies.
  29. test: /\.(jpe?|pn)g$/,
  30. use: [
  31. // Use object format instead of string to pass options to a loader.
  32. {
  33. loader: "file-loader",
  34. },
  35. ]
  36. }
  37. ]
  38. }
  39. };