-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
111 lines (103 loc) · 2.71 KB
/
webpack.config.js
File metadata and controls
111 lines (103 loc) · 2.71 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
/**
* webpack.config.js
**/
const webpack = require('webpack');
const path = require('path');
const pkg = require('./package.json');
const config = {};
const HtmlWebpackPlugin = require('html-webpack-plugin');
config.name = pkg.name;
config.source = path.resolve(__dirname, 'src');
config.paths = {
app: path.resolve(__dirname, 'app'),
public: '/',
content: './app/',
assets: './assets/',
scripts: './assets/scripts/',
styles: './assets/styles/',
images: './assets/images/',
fonts: './assets/fonts/'
};
config.relativePaths = {
fonts: '../fonts/',
images: '../images/'
};
config.filenames = {
js: config.paths.scripts + config.name + '.[name]',
lib: config.paths.scripts + config.name + '.lib.js',
css: config.paths.styles + config.name + '.css'
};
config.libs = [];
Object.keys(pkg.dependencies).forEach(function (item) {
config.libs.push(item);
});
const devConfig = {
context: config.source,
entry: {
'js': [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:8080/',
'webpack/hot/only-dev-server',
'./scripts/index.js'
],
'lib': config.libs
},
output: {
filename: config.filenames.js,
path: config.paths.app,
publicPath: config.paths.public
},
module: {
rules: [
{
test: /\.tpl?$/i,
loader: 'html-loader',
options: {
attrs: ["img:src", "link:href"]
}
},
{
test: /\.(js|jsx)?$/i,
enforce: 'pre',
loader: 'eslint-loader'
},
{
test: /\.(js|jsx)?$/i,
loader: 'babel-loader'
}
]
},
resolve: {
modules: [
'node_modules',
config.source
],
extensions: ['.js', '.jsx', '.json']
},
devtool: 'eval-source-map',
devServer: {
publicPath: config.paths.public,
contentBase: config.paths.content,
hot: true,
historyApiFallback: true
},
plugins: [
new HtmlWebpackPlugin({
template: config.source + '/templates/static/index.tpl'
}),
new webpack.DefinePlugin({
'__DEV__': true,
'process.env': {
'NODE_ENV': JSON.stringify('development')
}
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'lib',
filename: config.filenames.lib,
minChunks: Infinity
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin()
]
};
module.exports = devConfig;