This repository has been archived by the owner on Jan 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.example.config.js
79 lines (70 loc) · 1.94 KB
/
webpack.example.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
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var path = require("path");
var DEV = process.env.WEBPACK_ENV !== "production";
var outputFolder = path.resolve('dist');
var outputFileName = "example.js";
var entry = path.resolve("src/example/example.jsx");
var plugins = [
new webpack.NoErrorsPlugin(),
new HtmlWebpackPlugin({
template: path.resolve("src/example/example.html"),
hash: false,
filename: 'example.html',
inject: false,
minify: false
})
];
if (!DEV) {
plugins.push(new ExtractTextPlugin("example.css"));
}
function extractCSS(loaders) {
/*
If not running in webpack HMR, we need to extract compiled CSS into standalone files
http://stackoverflow.com/questions/34133808/webpack-ots-parsing-error-loading-fonts/34133809#34133809
*/
if (DEV) {
return "style!" + loaders;
}
return ExtractTextPlugin.extract("style-loader", loaders);
}
var config = {
entry: [entry],
output: {
path: outputFolder,
filename: outputFileName,
publicPath: ""
},
bail: true,
externals: {
"jquery": "var $"
},
module: {
loaders: [
{
test: /(\.jsx|\.js)$/,
loader: 'babel',
exclude: /node_modules/
},
{
test: /\.scss$/,
include: /src/,
loader: extractCSS("css?modules&sourceMap&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!sass?sourceMap")
}
]
},
resolve: {
root: path.resolve('src'),
extensions: ['', '.js', '.jsx']
},
plugins: plugins
};
if (!DEV) {
config.module.loaders.push({
test: /(\.jsx|\.js)$/,
loader: "eslint-loader",
exclude: /node_modules/
});
}
module.exports = config;