-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
75 lines (74 loc) · 2.66 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
const path = require('path') //path是Nodejs中的基本包,用来处理路径
const htmlWebpackPlugin = require('html-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
module.exports = {
cache: false,
mode: 'none', // no defaults
entry: path.resolve(__dirname, './src/main.js'),
output: {
path: path.resolve(__dirname, './dist'),
// publicPath: '/dist/',
},
resolve: {
alias: {
'@': path.resolve(__dirname, "src"),
}
},
module: {
rules: [
//针对不同类型的文件,我们定义不同的识别规则,最终目的都是打包成js文件
{
test: /\.vue$/,
exclude: /node_modules/,
use: [
'vue-loader', //处理.vue文件
],
},
{// 添加这个json,解决如上的报错问题
test: /\.(scss|css)$/,
use: ['style-loader', 'css-loader', 'sass-loader']
},
{
test: /\.js?$/, //处理js
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/react'],
plugins: [
[
require('@babel/plugin-proposal-decorators'),
{legacy: true},
],
],
},
},
],
include: path.resolve(__dirname, 'src'),
exclude: /node_modules/,
},
{
test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
loader: 'url-loader'
},
{
test: /\.(png|gif|jpg|jpeg|svg)$/, //处理图片
exclude: /node_modules/,
use: ['url-loader'],
},
],
},
plugins: [
new htmlWebpackPlugin({
template: './index.html',
}),
new VueLoaderPlugin(), // vueLoader插件 允许你以一种名为单文件组件的格式撰写 Vue 组件
],
devServer: {
contentBase: path.join(__dirname, './dist'),
host: 'localhost', // 可以设置0.0.0.0 ,这样设置你可以通过127.0.0.1或则localhost去访问
open: true, // 项目启动时,会默认帮你打开浏览器
port: 8088,
// hot: true //在单页面应用开发中,我们修改了代码后是整个页面都刷新,开启hot后,将只刷新对应的组件
},
}