forked from gabyliu/webpack_package
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
77 lines (67 loc) · 2.59 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
var webpack = require('webpack');
var path = require('path');
var fs = require("fs");
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var PluginTrave = require('./plugins/traveFile');//我的插件
//PackagePlugin.main();
var entryJson = {},
configPlugins = [
new ExtractTextPlugin('[name].[hash:4].css')
],
htmlPlugin;
//整个文件加的index.js
//widget不能作为入口文件,作为入口文件,会使page找不到widgets
var init = {
entries: function(){
var fileList = PluginTrave.getFileList(['src/']);
for(var i = 0; i < fileList.length; i++){
if(path.basename(fileList[i]) == 'index.js'){
if(path.dirname(fileList[i]).indexOf('widgets') >= 0){
entryJson[path.dirname(fileList[i].replace('src\\', '')) + '\\index'] = [__dirname + '/' + path.normalize(fileList[i])];
}else{
entryJson[path.dirname(fileList[i].replace('src\\', '')) + '\\index'] = __dirname + '/' + path.normalize(fileList[i]);
}
configPlugins.push(new HtmlWebpackPlugin({
filename: path.dirname(fileList[i]).replace('src\\', '') + '/index.html',
chunks: [path.normalize(path.dirname(fileList[i]).replace('src\\', '') + '/index')],
template : path.dirname(fileList[i]) + '/index.ejs',
}));
}
}
}
};
init.entries();
var babelPresets = {presets: ['react', 'es2015']},
packagePresets = {widgets: __dirname + '/src/widgets/'};//组件们所在的目录
module.exports = {
//devtool: 'eval-source-map',//配置生成Source Maps,选择合适的选项
devtool: 'source-map',
entry: entryJson,
output: {
path: path.join(__dirname, "dist/"),//
filename: "[name].[hash:4].js"
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loaders: ['babel-loader?'+JSON.stringify(babelPresets), 'package-loader?' + JSON.stringify(packagePresets)]//在webpack的module部分的loaders里进行配置即可
},
{
test : /\.(less|css)$/,
exclude: /node_modules/,
loader: ExtractTextPlugin.extract('style', 'css!less')
},
{
// 图片加载器,雷同file-loader,更适合图片,可以将较小的图片转成base64,减少http请求
// 如下配置,将小于8192byte的图片转成base64码
test: /\.(png|jpg|gif)$/,
exclude: /node_modules/,
loader: 'url?limit=1&name=../../../../../htdocs/zh_CN/base/images/[name].[ext]',
}
]
},
plugins: configPlugins,
};