-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.dev.js
150 lines (144 loc) · 3.76 KB
/
webpack.config.dev.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
138
139
140
141
142
143
144
145
146
147
148
149
150
const polyfill = []
const os = require('os');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const resolve = dir => path.resolve(__dirname, dir);
const webpack = require('webpack')
const isDev = process.env.NODE_ENV == 'development'
let WEB_ENV = process.env.WEB_ENV;
let productionDir = `${__dirname}/dist`;
if( os.type() !='Windows_NT'){
productionDir = `/mnt/market/html5video/`
}
let entry = '';
let framework = '';
switch( WEB_ENV ){
case 'lib-react':
entry = './src/demo/index.react.js';
framework = 'react';
break;
case 'lib-vue':
entry = './src/demo/index.vue.js';
framework = 'vue';
break;
case 'react':
entry = './src/index.react.js';
framework = 'react';
break;
case 'vue':
entry = './src/index.vue.js';
framework = 'vue';
break;
}
console.log('entry', entry)
const config = {
entry: entry,
output: {
path: isDev ? `${__dirname}/dist`:productionDir,
filename: 'index.js',
},
resolve: {
// 设置别名
extensions: ['.js', '.jsx'],
alias: {
'@': resolve('src')// 这样配置后 @ 可以指向 src 目录
}
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test:/\.styl(us)?$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
sourceMap: true
}
//选项的作用使用来提高效率的。
},
'stylus-loader'
]
},
{
test:/\.css$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
sourceMap: true
}
//选项的作用使用来提高效率的。
},
'stylus-loader'
]
},
{
test: /\.(jsx)$/, exclude: /node_modules/, loader: 'babel-loader'
},
{
test: /\.js$/,
loader: 'babel-loader', query: {compact: false}
},
{
test: /\.scss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1
}
},
'postcss-loader',
'sass-loader'
]
},
{
test:/\.less$/,
exclude: /node_modules/,
use: ['style-loader', 'css-loader', 'postcss-loader', 'less-loader']
},
{
test: /\.(png|jpe?g|gif|psd|svg|icon)$/,
loader: 'url-loader?limit=8192&name=images/[hash:8].[name].[ext]'
}
]
},
mode: 'production',
plugins: [
new webpack.DefinePlugin({
'framework': JSON.stringify( framework ),
//'framework': JSON.stringify('vue'),
'dev':JSON.stringify(process.env.NODE_ENV)
}),
new HtmlWebpackPlugin( { filename: "mvvm.html", template: path.join(__dirname, "./src/mvvm.html") } ),
//new MiniCssExtractPlugin({filename: 'style.css',})
new webpack.HotModuleReplacementPlugin()
],
devServer: {
//contentBase: false, // boolean | string | array, static file location
contentBase:"./dist",
compress: true, // enable gzip compression
historyApiFallback: true, // true for index.html upon 404, object for multiple paths
hot: true, // hot module replacement. Depends on HotModuleReplacementPlugin
https: false, // true for self-signed, object for cert authority
noInfo: true, // only errors & warns on hot reload
host:"0.0.0.0"
// ...
},
optimization: {
minimize: false
}
}
config.plugins.push(new VueLoaderPlugin())
module.exports = config;