加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
webpack.config.js 2.91 KB
一键复制 编辑 原始数据 按行查看 历史
yrxuxd25185 提交于 2019-01-30 17:03 . add third grid-layout
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin"); //生成HTML文件
const eslintFormatter = require("react-dev-utils/eslintFormatter");
module.exports = {
entry: path.join(__dirname, "examples/src/index.js"), //入口文件
output: {
filename: "[name].bundle.js" //输出文件名
},
mode: "development",
devtool: "cheap-module-source-map",
resolve: {
extensions: [".js", ".jsx", "tsx", "ts"]
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: "babel-loader",
include: /src/,
exclude: /node_modules/,
options: {
plugins: [
[
"import",
{ libraryName: "antd", libraryDirectory: "es", style: "css" }
]
], //antd组件按需引入
cacheDirectory: true
}
},
{
test: /\.tsx?$/,
loader: "ts-loader",
exclude: /node_modules/
},
{
test: /\.(js|jsx)$/,
enforce: "pre",
use: [
{
options: {
formatter: eslintFormatter,
eslintPath: require.resolve("eslint")
},
loader: require.resolve("eslint-loader")
}
],
exclude: /node_modules/
},
{
test: /\.scss|css$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" },
{ loader: "sass-loader" }
]
},
{
test: /\.(png|svg|jpg|gif)$/i,
use: [
{
loader: "url-loader",
options: {
limit: 10000,
mimetype: "image/png",
fallback: "responsive-loader"
}
}
]
},
{
test: /\.(woff|woff2|svg|tff|eot)$/i,
use: [
{
loader: "url-loader",
options: {
limit: 10000,
fallback: "responsive-loader"
}
}
]
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, "examples/index.html"),
filename: "./index.html"
}),
new webpack.HotModuleReplacementPlugin() //配合 webpack-dev-server启用HMR
],
devServer: {
port: 3001,
open: true,
hot:true,
historyApiFallback: true, //不跳转,在开发单页应用时非常有用,它依赖于HTML5 history API, 如果设置为true,所有的跳转,将指向index.html
contentBase: path.join(__dirname, "public"), //本地服务器所加载的页面所在的目录
proxy: {
//凡是 '/api' 开头的http请求,都会被代理到localhost:3000上,实际上后端做了一次转发 ,后端去3000端口拿到数据后,又返回的,这里并不是真正的服务,真正的服务在3000端口上
"/api": {
target: "http://localhost:3000",
secure: false
}
}
}
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化