forked from LubinPark/react-redux-router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
executable file
·134 lines (130 loc) · 4.62 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
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
/**
* 开发环境配置
*/
"use strict";
let path = require('path');
let fs = require('fs');
let webpack = require('webpack');
let autoprefixer = require('autoprefixer'); //添加浏览器前缀
let ExtractTextPlugin = require("extract-text-webpack-plugin"); //独立拆分css
var CopyWebpackPlugin = require('copy-webpack-plugin'); //复制文件
var OpenBrowserPlugin = require('open-browser-webpack-plugin'); //打开浏览器
let ip = require('ip');
let myIp=ip.address();
let pxtorem = require('postcss-pxtorem');//px转rem
process.env.NODE_ENV = 'development';
//入口程序,解析app.js
let getEntries = (function() {
let _entries = {};
let _basePath = path.join(__dirname, './src');
let _entryFile = 'index.js';
let _dirs = fs.readdirSync(_basePath);
_dirs.forEach(function(dir) {
let _path = path.join(_basePath, dir, _entryFile);
if (fs.existsSync(_path)) {
_entries[dir] = ['webpack/hot/dev-server',
'webpack-dev-server/client?http://' + myIp +
':' + process.env.npm_package_config_port, _path
];
}
});
return _entries;
})();
module.exports = {
/*
* babel参数
* */
babelQuery: {
presets: ['es2015', 'stage-0','react'],
plugins: ['transform-runtime', 'add-module-exports', 'typecheck',
"transform-decorators-legacy","babel-plugin-transform-decorators-legacy","transform-class-properties",
"transform-object-assign"
],
cacheDirectory: true
},
devtool: "source-map", //产生source的方式
entry: getEntries,
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/dist',
filename: '[name]/[name].bundle.js',
chunkFilename: '[name]/[name].bundle.js'
},
devServer: {
historyApiFallback: true,
},
module: {
loaders: [{
test: /\.(js|jsx)$/,
loader: 'babel?presets[]=react,presets[]=es2015,presets[]=stage-0',
exclude: /node_modules/,
query: this.babelQuery
}, {
test: /\.scss$/,
loader: ExtractTextPlugin.extract('css?sourceMap!postcss!sass?sourceMap')
}, {
test: /\.css$/,
loader: ExtractTextPlugin.extract('css?sourceMap!postcss')
}, {
test: /\.(png|jpg)$/,
loader: "url?name=[path][name].[ext]&limit=8192"
}]
},
postcss: function () {
return [pxtorem({
rootValue: 40,
propWhiteList: [],
selectorBlackList: [/^html$/]
})]
},
resolve: {
extensions: ['','.web.js','.js','.jsx', '.scss', 'css', 'png', 'jpg', 'jpeg'],
alias: { //模块别名定义,方便后续直接引用别名,无须多写长长的地址
'loading': path.join(__dirname, './src/home/components/loading'),//loading组件
'btn': path.join(__dirname, './src/home/components/btn'),//按钮组件
'banner': path.join(__dirname, './src/home/components/banner'),//banner组件
'alert': path.join(__dirname, './src/home/components/alert'),//alert组件
'inputGroup': path.join(__dirname, './src/home/components/inputGroup'),//inputGroup组件
'input': path.join(__dirname, './src/home/components/input'),//input组件
'image': path.join(__dirname, './src/home/components/image'),//image组件
'checkbox': path.join(__dirname, './src/home/components/checkbox'),//checkbox组件
'getPage': path.join(__dirname, './src/home/components/GetPage.js'),//getPage
'getData': path.join(__dirname, './src/home/components/GetData.js'),//getData
'getInput': path.join(__dirname, './src/home/components/GetInput.js'),//getInput
'getNextPage': path.join(__dirname, './src/home/components/GetNextPage.js'),//getNextPage
'roll': path.join(__dirname, './src/home/components/roll'),//roll组件
'publicJs': path.join(__dirname, './src/home/lib/public.js'),//公共js
'session': path.join(__dirname, './src/home/lib/session.js'),//session
'verticalRoll': path.join(__dirname, './src/home/components/verticalRoll'),//垂直roll组件
'accordion': path.join(__dirname, './src/home/components/accordion'),//可折叠
}
},
plugins: [
new OpenBrowserPlugin({
url: 'http://' + myIp+ ':' + process.env.npm_package_config_port
}),
//热加载
new webpack.HotModuleReplacementPlugin(),
/**
* 调用dll的内容
* @type {[type]}
*/
new webpack.DllReferencePlugin({
context: __dirname,
//这里引入manifest文件
manifest: require('./dist/vendor-manifest.json')
}),
/**
* 提取公共部分js
* @type {String}
*/
new webpack.optimize.CommonsChunkPlugin({
name: 'commons',
filename: 'commons.js'
}),
/**
* 提取css文件
*/
new ExtractTextPlugin("[name]/[name].bundle.css")
]
}