forked from steamerjs/steamer-react
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.dev.js
executable file
·161 lines (151 loc) · 5.48 KB
/
webpack.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
151
152
153
154
155
156
157
158
159
160
161
'use strict';
const path = require('path'),
utils = require('./config/utils'),
webpack = require('webpack');
var config = require('./config/config'),
nodeModulesPath = path.join(__dirname, 'node_modules'),
parentNodeModulePath = path.join(path.dirname(__dirname), 'node_modules');
var HtmlResWebpackPlugin = require('html-res-webpack-plugin');
var CopyWebpackPlugin = require("copy-webpack-plugin");
/**
* [devConfig config for development mode]
* @type {Object}
*/
var devConfig = {
entry: {
index: [path.join(config.path.src, "/page/index/main.js")],
spa: [path.join(config.path.src, "/page/spa/main.js")],
},
output: {
publicPath: config.defaultPath,
path: path.join(config.path.dist),
filename: "js/[name]" + config.chunkhash + ".js",
chunkFilename: "js/chunk/[name]" + config.chunkhash + ".js",
},
module: {
loaders: [
{
test: /\.js?$/,
loaders: ['react-hot'],
exclude: /node_modules/,
},
{
test: /\.js?$/,
loader: 'babel',
query: {
cacheDirectory: false,//'/webpack_cache/',
plugins: ['transform-decorators-legacy'],
presets: [
'es2015-loose',
'react',
]
},
exclude: /node_modules/,
},
{
test: /\.css$/,
loader: "style-loader!css-loader",
include: path.resolve(config.path.src)
},
{
test: /\.less$/,
loader: "style-loader!css-loader!less-loader",
include: [parentNodeModulePath, nodeModulesPath, path.resolve(config.path.src)]
},
{
test: /\.scss$/,
loader: "style-loader!css-loader!sass-loader",
include: [parentNodeModulePath, nodeModulesPath, path.resolve(config.path.src)]
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
"url-loader?limit=1000&name=img/[name]" + config.hash + ".[ext]",
],
include: path.resolve(config.path.src)
},
{
test: /\.ico$/,
loader: "url-loader?name=[name].[ext]",
include: path.resolve(config.path.src)
},
{
test: /\.(woff|woff2|eot|ttf|svg)(\?.*$|$)/,
loader: 'url-loader?importLoaders=1&limit=10000&name=fonts/[name]' + config.hash + '.[ext]'
},
],
noParse: [
]
},
resolve: {
moduledirectories:['node_modules', config.path.src],
extensions: ["", ".js", ".jsx", ".es6", "css", "scss", "png", "jpg", "jpeg", "ico"],
alias: {
'redux': 'redux/dist/redux',
'react-redux': 'react-redux/dist/react-redux',
'classnames': 'classnames',
'utils': path.join(config.path.src, '/js/common/utils'),
'spin': path.join(config.path.src, '/js/common/spin'),
'spinner': path.join(config.path.src, '/page/common/components/spinner/'),
'report': path.join(config.path.src, '/js/common/report'),
'touch': path.join(config.path.src, '/page/common/components/touch/'),
'scroll':path.join(config.path.src, '/page/common/components/scroll/'),
'immutable-pure-render-decorator': path.join(config.path.src, '/js/common/immutable-pure-render-decorator'),
'pure-render-decorator': path.join(config.path.src, '/js/common/pure-render-decorator'),
}
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoErrorsPlugin(),
new CopyWebpackPlugin([
{
from: 'src/libs/',
to: 'libs/'
}
]),
],
watch: true, // watch mode
// devtool: "#inline-source-map",
};
devConfig.addPlugins = function(plugin, opt) {
devConfig.plugins.push(new plugin(opt));
};
config.html.forEach(function(page) {
devConfig.addPlugins(HtmlResWebpackPlugin, {
filename: page + ".html",
template: "src/" + page + ".html",
favicon: "src/favicon.ico",
jsHash: "[name]" + config.chunkhash + ".js",
cssHash: "[name]" + config.chunkhash + ".css",
isHotReload: true,
templateContent: function(tpl) {
// 生产环境不作处理
if (!this.options.isWatch) {
return tpl;
}
// 开发环境先去掉外链react.js
var regex = new RegExp("<script.*src=[\"|\']*(.+).*?[\"|\']><\/script>", "ig");
tpl = tpl.replace(regex, function(script, route) {
if (!!~script.indexOf('react.js') || !!~script.indexOf('react-dom.js')) {
return '';
}
return script;
});
return tpl;
},
htmlMinify: null
});
});
devConfig.addPlugins(webpack.HotModuleReplacementPlugin);
devConfig.addPlugins(webpack.DefinePlugin, {
"process.env": {
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
},
"isNode": false,
"console.dev": function(msg) { console.log(msg); }
});
module.exports = devConfig;