webpack.config.js 1.4 KB

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