-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.release.js
141 lines (133 loc) · 3.97 KB
/
webpack.release.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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const argv = require('yargs').argv;
var isProduction = process.env.NODE_ENV === 'production';
// 构建目录,构建入口, 如果没有指定模块则默认全部模块
var activeModule = argv.define || 'all';
var modules = ['index', 'task', 'ask', 'find', 'contact', 'user', 'centre', 'login', 'setting'];
var outputPath = path.resolve(__dirname, 'public/');
var config = {
entry: {
vendor: ['jquery', 'vue', 'vuex', 'axios']
},
output: {
//filename: 'js/[name]-[chunkhash:8].js',
filename: 'js/[name].js',
path: outputPath
},
module: {
rules: [{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
})
}, {
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'postcss-loader', 'resolve-url-loader', 'sass-loader?sourceMap']
})
}, {
test: /\.ejs$/,
use: 'ejs-compiled-loader'
},
{
test: /\.vue$/,
use: 'vue-loader'
},
{
test: /\.js$/,
use: 'babel-loader'
}, {
test: /\.(png|jpg|jpeg|gif)(\?.+)?$/,
use: [{
loader: 'url-loader',
options: {
limit: 10000,
name: '[name].[ext]',
publicPath: '../',
outputPath: 'img/'
}
}]
}, {
test: /\.(eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
use: [{
loader: 'url-loader',
options: {
limit: 1000,
name: '[name].[ext]',
publicPath: '../',
outputPath: 'font/'
}
}]
}]
},
resolve: {
alias: {
mock: path.resolve(__dirname, 'src/common/js/mock/mock.js'),
vue: 'vue/dist/vue.js'
}
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
//Popper: ['popper.js', 'default']
}),
new CopyWebpackPlugin([
{ from: 'node_modules/bootstrap/dist/css', to: 'vendor/bootstrap/css/' },
{ from: 'node_modules/tinymce/plugins', to: 'js/plugins' },
{ from: 'node_modules/tinymce/themes', to: 'js/themes' },
{ from: 'node_modules/tinymce/skins', to: 'js/skins' }
]),
// 抽出样式
new ExtractTextPlugin({
//filename: 'css/[name]-[chunkhash:8].css'
filename: 'css/[name].css'
}),
// 抽出公共文件vendor依赖,manifest运行时信息
new webpack.optimize.CommonsChunkPlugin({
//name: ['vendor', 'manifest']
name: 'vendor',
minChunks: Infinity,
}),
// 定义组件内环境变量
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
// 代码压缩优化
new UglifyJsPlugin(),
// 文件清单
new ManifestPlugin()
]
};
console.log('activeModule', activeModule)
if (activeModule === 'all') {
modules.forEach((n, i) => {
config.entry[n] = path.resolve(__dirname, 'src/', n, n + '.js');
// //页面集成
config.plugins.push(new HtmlWebpackPlugin({
chunks: ['vendor',n],
template: path.resolve(__dirname, 'src/', n, n + '.ejs'),
filename: 'template/' + n + '.html'
}));
console.log('entry', path.resolve(__dirname, 'src/', n, n + '.js'));
})
} else {
config.entry[activeModule] = path.resolve(__dirname, 'src/', activeModule, activeModule + '.js');
//页面集成
config.plugins.push(new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src/', activeModule, activeModule + '.ejs'),
filename: 'template/' + activeModule + '.html'
}));
console.log('entry', path.resolve(__dirname, 'src/', activeModule, activeModule + '.js'));
}
module.exports = config;