Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. 新建```webpack.json.js```
- ```javascript
- module.exports = {
- entry: './src/index.js',
- output: {
- path: 'bundle',
- filename: 'bundle.js'
- },
- module: {
- loaders: [
- {
- test: /\.js$/,
- exclude: /node_modules/,
- loaders: ['react-hot', 'babel-loader']
- },
- {
- test: /\.css$/,
- loader: 'style-loader!css-loader'
- }
- ]
- }
- };
- ```
- ```entry```: the start point of react app
- ```output```: webpack needs to know where it should output and save transformed code, we can also use ***path*** to locate the location
- ```modules```: we define which transformation to make on our code
- > 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
- 2. Webpack Dev Server
- Runs ```npm install --save-dev webpack-dev-server``` to install the webpack dev server
- 3. CSS loader
- We can bundle our stylesheets into a single bundled JavaScript file via CSS loader. Simply run ```npm install --save-dev style-loader css-loader```
- > 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