Repository navigation
Expand file tree
/
Copy pathwebpack.config.dev.js
More file actions
127 lines (109 loc) · 3.94 KB
/
Copy pathwebpack.config.dev.js
File metadata and controls
127 lines (109 loc) · 3.94 KB
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
/*
* @Author: jacky.yang
* @Date: 2018-03-16 17:06:42
* @Last Modified by: jacky.yang
* @Last Modified time: 2018-03-30 11:48:49
*/
'use strict'
const webpack = require('webpack');
const path = require('path');
const rimraf = require('rimraf'); // 删除文件
// extract-text-webpack-plugin
// 该插件的主要是为了抽离css样式,防止将样式打包在js中引起页面样式加载错乱的现象
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const TemplatePlugin = require('./webpack/templatePlugin'); // 模版生成工具
const config = require('./webpack/config');
const glob = require('glob'); // 允许你使用 *等符号,写一个glob规则,匹配对应规则的文件
const yamlFrontMatter = require('yaml-front-matter'); // 使用一段 YAML 语法的头部文本来标记源文件
const myConfig = require('./webpack/myConfig');
const loader = require('./webpack/loader'); // 各种loader设置文件
var projects = config.projects;
var webpackObj = [];
projects.forEach(function(project) {
var OUTPUTPATH_DEV = config.OUTPUTPATH_DEV + '/'+ project;
rimraf.sync(OUTPUTPATH_DEV);
// // html模板路径
const pageFiles = glob.sync('src/projects/' + project + '/v/**/*', {
nodir: true
});
var entries = {};
var plugins = [
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor' + project,'manifest'],
minChunks: Infinity
}),
new ExtractTextPlugin('styles/[name].css' + config.HASH_LENGTH('contenthash')),
// new webpack.HashedModuleIdsPlugin(),
//把一个全局变量插入到所有的代码中,支持jQuery plugin的使用;使用ProvidePlugin加载使用频率高的模块
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
'window.$': 'jquery'
})
];
plugins.push(
new TemplatePlugin({
project: project,
// host: CONFIG.BASE_URL.dev,
pages: 'src/projects/' + project,
layout: 'src/layouts',
partial: 'src/partials',
// addTemplateHelpers: CONFIG.addTemplateHelpers,
// 输出路径 {path}目标文件路径
distPath: function(filepath) {
filepath = filepath.replace(/\\/g, '\/');
var reg = /\/src\/projects\/(.*)\/v\/(.*)/ig;
var regObj = reg.exec(filepath);
var pName = regObj[1];
var file = regObj[2]
file = myConfig.ECLIPSE ? path.resolve(myConfig.JSP_DEV_PATH, myConfig.FOLDERNAME+'/'+pName + '/v/' + file) : path.resolve(myConfig.JSP_DEV_PATH, '.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/' + myConfig.FOLDERNAME +'/'+ pName + '/v/' + file);
return file;
}
})
)
pageFiles.forEach(function(item) {
var pageData = yamlFrontMatter.loadFront(item);
var entry = pageData.entry && pageData.entry.replace(/\.js$/, '');
var chunks = [];
if (entry) {
chunks = ['manifest', 'vendor' + project];
if (entry !== 'common') {
chunks.push(entry);
entries[entry.replace('/scripts/', '/')] = [path.join(__dirname, 'src/projects', entry)];
// entries[entry.replace('/scripts/', '/')] = [path.join(__dirname, 'src/projects', entry)];
console.log('entries3333'+JSON.stringify(entries));
}
}
});
entries['vendor_' + project] = ['jquery', 'libs/bootstrap', 'scripts/common_' + project];
// entries['vendor_match'] = config.vendor_match;
console.log('entriesxxxxx'+JSON.stringify(entries));
var loaderAry = loader();
webpackObj.push({
entry: entries,
output: {
path: OUTPUTPATH_DEV, // resolve('dev')
filename: 'scripts/[name].js' + config.HASH_LENGTH('chunkhash'), // name = 'match'
chunkFilename: 'scripts/[name].js' + config.HASH_LENGTH('chunkhash'),
publicPath: config.STATIC_URL.DEV + '/dev/'+project+'/' // config.STATIC_URL.DEV = http://dev.choice.com:9999
},
module: {
rules:loaderAry
},
resolve: {
alias: config.alias
},
plugins: plugins,
devServer: {
stats: 'minimal',
port: config.PORT,
host: '0.0.0.0',
headers: {
'Access-Control-Allow-Origin': '*'
},
disableHostCheck: true
}
});
})
module.exports = webpackObj;