[WEBPACK] 5. Webpack : Tạo Project ReactJS (

https://www.valentinog.com/blog/babel/

Ví dụ đã hoàn thành :)

Chú ý: Ta có thể viết gọn babel-loader

babel-loader như sau :))

C:\Users\Administrator\Desktop\abc\webpack.config.js

Trước

const path = require('path');

module.exports = {
  entry: './src/app.js',
  output: {
    path: path.join(__dirname, 'public'),
    filename: 'bundle.js'
  },
  module: {
    rules: [{
        test: /\.js$/,
        exclude: /node_modules/,
        use: [{
          loader: 'babel-loader',
          options: {
            presets: ["@babel/preset-env", "@babel/preset-react"],
            plugins: [
              '@babel/plugin-proposal-class-properties'
            ]

          }
        }]
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      }
    ]
  },
  devtool: 'cheap-module-eval-source-map',
  devServer: {
    contentBase: path.join(__dirname, 'public')
  }
};

C:\Users\Administrator\Desktop\abc\webpack.config.js

Sau

C:\Users\Administrator\Desktop\abc.babelrc

Đọc thêm

https://viblo.asia/p/reactjs-ket-hop-voi-webpack-part-1-Eb85ogr052G

https://viblo.asia/p/tu-setup-reactjs-project-co-ban-voi-webpack-4-va-babel-7-phan-1-63vKj2pxK2R

https://hashinteractive.com/blog/complete-guide-to-webpack-configuration-for-react/

C:\Users\Administrator\Desktop\webpack\package.json

C:\Users\Administrator\Desktop\webpack\webpack.config.js

Hoặc chúng ta có thể chỉnh định tên thư mục và file trong trường hợp này là public và bundle.js

C:\Users\Administrator\Desktop\webpack\src\index.html

C:\Users\Administrator\Desktop\webpack\src\js\components\Form.js

C:\Users\Administrator\Desktop\webpack\src\index.js

C:\Users\Administrator\Desktop\webpack.babelrc

Last updated