Advertisement
yoesoff

webpack

Jan 2nd, 2018
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!-- index.html -->
  2. <!DOCTYPE html>
  3. <html lang="en">
  4.   <head>
  5.     <meta charset="utf-8">
  6.     <title>Hello webpack</title>
  7.   </head>
  8.   <body>
  9.     <div id="root"></div>
  10.     <script src="dist/bundle.js"></script>
  11.   </body>
  12. </html>
  13. // src/app.js
  14. const root = document.querySelector('#root')
  15. root.innerHTML = `<p>Hello webpack.</p>`
  16. // webpack.config.js
  17. const webpack = require('webpack')
  18. const path = require('path')
  19.  
  20. const config = {
  21.   context: path.resolve(__dirname, 'src'),
  22.   entry: './app.js',
  23.   output: {
  24.     path: path.resolve(__dirname, 'dist'),
  25.     filename: 'bundle.js'
  26.   },
  27.   module: {
  28.     rules: [{
  29.       test: /\.js$/,
  30.       include: path.resolve(__dirname, 'src'),
  31.       use: [{
  32.         loader: 'babel-loader',
  33.         options: {
  34.           presets: [
  35.             ['es2015', { modules: false }]
  36.           ]
  37.         }
  38.       }]
  39.     }]
  40.   }
  41. }
  42.  
  43. module.exports = config
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement