Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. 1. 新建```webpack.json.js```
  2. ```javascript
  3. module.exports = {
  4. entry: './src/index.js',
  5.  
  6. output: {
  7. path: 'bundle',
  8. filename: 'bundle.js'
  9. },
  10.  
  11. module: {
  12. loaders: [
  13. {
  14. test: /\.js$/,
  15. exclude: /node_modules/,
  16. loaders: ['react-hot', 'babel-loader']
  17. },
  18. {
  19. test: /\.css$/,
  20. loader: 'style-loader!css-loader'
  21. }
  22. ]
  23. }
  24.  
  25. };
  26. ```
  27. ```entry```: the start point of react app
  28. ```output```: webpack needs to know where it should output and save transformed code, we can also use ***path*** to locate the location
  29. ```modules```: we define which transformation to make on our code
  30. > we want our react app to transpile JSX to JavaScript and ES2015 to ES5. We specify ***babel-loader*** to make webpack know to checkout the ```.babelrc``` file
  31.  
  32. 2. Webpack Dev Server
  33. Runs ```npm install --save-dev webpack-dev-server``` to install the webpack dev server
  34.  
  35. 3. CSS loader
  36. We can bundle our stylesheets into a single bundled JavaScript file via CSS loader. Simply run ```npm install --save-dev style-loader css-loader```
  37. > the ***style-loader*** is going to embed the CSS in the bundle.js and the ***css-loader*** parses the css and applies it to the DOM.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement