-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
137 lines (134 loc) · 4.19 KB
/
webpack.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const projectName = "w-map";
const outPath = "build";
const debugPath = "dist";
const path = require('path');
const webpack = require('webpack');
const ExTextPlg = require("extract-text-webpack-plugin");
const HtmlPlg = require('html-webpack-plugin');
var DEBUG = true;
if(process.env.NODE_ENV == 'production'){
DEBUG = false;
}
module.exports = {
entry: {
index:'index'
},
output: {
path: path.resolve(__dirname, DEBUG?debugPath:outPath), // 输出的路径
// publicPath: '/icommunity-overview/', // 输出的路径
//sourceMapFilename: 'maps/[name].map',
chunkFilename: "[name].index.js"
},
devtool: DEBUG ? 'inline-source-map':"inline-source-map",
devServer: {
contentBase: debugPath, //本地服务器所加载的页面所在的目录
port: 7687,
host: '127.0.0.1',
inline: true, //实时刷新
historyApiFallback: true, //不跳转
hot: true, // 开启热重载
// sockHost: 'http://0.0.0.0:8888/icommunity-overview/sockjs-node',
// disableHostCheck: true,
},
resolve: {
extensions: ['.js', '.ts'],
mainFiles:["index", "daliTree", "ace"] ,
alias: {
wmap: path.join(__dirname, 'src'),
index: path.resolve(__dirname, 'src','deom'),
daliTree: path.resolve(__dirname, 'src','daliTree','src'),
ace: path.resolve(__dirname, 'src','deom','lib','ace.js')
}
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['latest'] //按照最新的ES6语法规则去转换
}
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.less$/,
exclude: /node_modules/,
loader: ExTextPlg.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
minimize: false
}
},{
loader: 'less-loader'
}
]
})
},{
test: /\.css$/,
exclude: /node_modules/,
loader: ExTextPlg.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
minimize: false
}
}
]
})
},{
test: /\.(png|jpg|gif|svg)$/,
loader: 'url-loader',
exclude: /node_modules/,
options: {
name: './images/[name].[ext]',
limit: 10192
}
}
]
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
name: "index",
chunks: "all",
minSize: 5,
maxSize: 10,
priority: 0
},
vendor: {
name: 'vendor',
test: /[\\/]node_modules[\\/]/,
chunks: 'all',
minSize: 5,
maxSize: 10,
priority: 10
}
}
}
},
plugins: [
new ExTextPlg("[name].css"),
new HtmlPlg({
alwaysWriteToDisk: true,
title: projectName,
template: `./src/deom/index.html`,//PS:相对目录是命令的执行位置
filename: `index.html`,//PS:相对目录是output的path位置
inject: "body",
debug: DEBUG,
isHashHistory: true,
chunks: ['index','ace'],
xhtml: true
})
]
}