-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.base.config.js
59 lines (58 loc) · 2.03 KB
/
webpack.base.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');//html插件,需要安装依赖项 npm install htmp-webpack-plugin --save-dev
const MiniCssExtractPlugin = require("mini-css-extract-plugin");//压缩css文件
module.exports = {
entry: {
main: path.join(__dirname, "./app/main.js"), //入口文件
common: ['react', 'react-dom']
},
output: {
path: path.join(__dirname, "./build"),//出口文件
filename: "[name].js",
},
resolve: {
extensions: ['.js', '.jsx', 'json', '.css'], //需要编译的文件类型
},
performance: {
hints: false
},
module: {
rules: [
{
test: /\.(js|jsx)?$/,
exclude: /(node_modules)/,
loader: 'babel-loader' , //jsx js转码配置
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'], //css转码,需要安装依赖项css-loader
},
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "less-loader", // compiles Sass to CSS
options:{javascriptEnabled:true}
}]
},
//{
// test: /\.html$/,
// use: [{loader: 'html-loader', options: {minimize: true}}]},
//{
// test: /\.(ico)$/,
// use: "raw-loader", //加载ico文件
//},
//{
// test:/\.(svg|png)$/, use:'file-loader', //加载文件
//}
]
},
plugins:[
new HtmlWebpackPlugin({ filename: "index.html", template: path.join(__dirname, "./public/index.html") }),
new MiniCssExtractPlugin({ filename: "[name].css", chunkFilename: "[id].css" })
]
}