Skip to content
/ ES6 Public

Webpack 4 + Babel 7 打造 ES6+ 前端环境。

Notifications You must be signed in to change notification settings

VincentTV/ES6

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ES6+ 前端环境

LICENSE

Webpack 4 + Babel 7 打造 ES6+ 前端环境。

  • 指定浏览器兼容 Babel 编译 ES6+ 代码。
  • CSS 自动加前缀、压缩、代码文件分离。
  • 热模块更新。

Getting Started

下载

git clone https://github.com/VincentTV/ES6.git

安装依赖

cd ES6
npm install

运行

npm run start

开始 ES6 编程。

编译输出

npm run build
ES6
│
├───dist	
│     ├───assets								
│     │     └───avatar-78c62249.png
│     ├───css
│     │     └───main.css
│     ├───index.html
│     └───main.bundle.js

webpack.config.js

const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const webpack = require("webpack");

module.exports = {
  entry: "./src/main.js",
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "[name].bundle.js"
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: "babel-loader"
      },
      {
        test: /\.css$/,
        use: [
          {
            loader: MiniCssExtractPlugin.loader,
            options: {
              publicPath: "../",
              hmr: true
            }
          },
          {
            loader: "css-loader",
            options: { importLoaders: 1 }
          },
          {
            loader: "postcss-loader",
            options: {
              plugins: [require("autoprefixer"), require("cssnano")]
            }
          }
        ]
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: "url-loader",
        options: {
          limit: 8192,
          name: "assets/[name]-[hash:8].[ext]"
        }
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: "src/index.html",
      filename: "index.html"
    }),
    new MiniCssExtractPlugin({
      filename: "css/[name].css"
    }),
    new webpack.HotModuleReplacementPlugin()
  ]
};

配置过程及详解,参考个人博客 Webpack4 + Babel7 打造 ES6+ 前端环境 | Vincent F0ng

About

Webpack 4 + Babel 7 打造 ES6+ 前端环境。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published