-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
108 lines (104 loc) · 3.06 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
const path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const webpack = require("webpack");
const isDev = process.env.NODE_ENV;
const kid = process.env.vip;
console.log(isDev);
// require("@babel/polyfill");
//console.log(global)
const HTMLplugin = require("html-webpack-plugin");
const resolve = dir => path.resolve(__dirname, dir);
var CopyWebpackPlugin = require('copy-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
let config = {
mode: 'development',
entry: {
content: path.join(__dirname,'src/index.js'),
background: path.join(__dirname,'src/background.js'),
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
resolve:{
extensions:['.js','.jsx','.json','.vue']//表示这几个的后缀名可以参略
},
module: {
rules: [
{
test: /\.vue$/,
loader: "vue-loader",
include: [path.resolve(__dirname, '../node_modules/element-ui'), path.resolve(__dirname, './src')]
},
{
test: /\.(jsx|js)$/,
loader: "babel-loader",
include: [path.resolve(__dirname, './src'), path.resolve(__dirname, '../node_modules/element-ui')]
},
{
test:/\.css$/,
use:[
'style-loader',
'css-loader'
]
},
{
test:/\.styl/,
use:[
'style-loader',
'css-loader',
'stylus-loader'
]
},
{
test:/\.(gif|jpg|jpeg|png|svg|ttf|woff)$/,
use:[
{
loader: "url-loader",
options: {
limit: 10000000,
}
}
]
}
]
},
plugins: [
new VueLoaderPlugin(),
new CopyWebpackPlugin([{
from: './src/assets/images',
to: 'src/assets/images',
},{
from: './src/manifest.json',
to: 'manifest.json'},
{
from: './src/icons',
to: 'icons'}
]),
new webpack.DefinePlugin({
NODE_ENV: isDev==='development' ? '"development"' : '"production"'
}),//定义可以在前端使用的全局变量
new HTMLplugin(),
// new ProgressBarPlugin(),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
]
};
if (isDev=="development") {
config.devtool = "#cheap-module-eval-source-map";
config.devServer = {
port: 8082,
host: '0.0.0.0',
overlay: {
errors:true,
},
hot:true
};
config.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
)
}
module.exports = config;