-
Notifications
You must be signed in to change notification settings - Fork 119
/
webpack.config.js
71 lines (71 loc) · 1.88 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
const path = require('path')
const webpack = require('webpack')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const resolve = dir => path.join(__dirname, '..', dir)
module.exports = {
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
devtool: process.env.NODE_ENV === 'production' ? '' : 'inline-source-map',
devServer: { // 检测代码变化并自动重新编译并自动刷新浏览器
contentBase: path.resolve(__dirname, 'dist'), // 设置静态资源的根目录
hot: true
},
entry: {
module: './src/exportModule.js',
build: './src/main.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
library: 'vueConciseSlider',
libraryTarget: 'umd',
umdNamedDefine: true
},
resolve: {
extensions: ['.js', '.vue', '.scss']
},
externals: {
vue: 'Vue'
},
module: {
// 加载器
rules: [
{
test: /\.(js|vue)$/,
loader: 'eslint-loader',
enforce: 'pre',
include: [resolve('src')],
options: {
formatter: require('eslint-friendly-formatter')
}
},
// 解析.vue文件
{
test: /.vue$/,
loader: 'vue-loader'
},
// 转化ES6的语法
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
// 编译css并自动添加css前缀
{
test: /\.css$/,
use: [ // 应用于模块的 loader 使用列表
'style-loader',
'css-loader'
]
},
// html模板编译
{ test: /\.(html|tpl)$/, loader: 'html-loader' }
]
},
plugins: [
// new webpack.optimize.UglifyJsPlugin(),
new VueLoaderPlugin(),
new BundleAnalyzerPlugin(),
new webpack.HotModuleReplacementPlugin()
]
}