-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
executable file
·98 lines (81 loc) · 2.74 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
// WEBPACK DOC : http://webpack.github.io/docs/
const webpack = require("webpack");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require("path");
const appScripts = [path.resolve(__dirname, "modules", "app.jsx")];
const modulesPath = path.resolve(__dirname, "modules");
const buildPath = path.resolve(__dirname, "build");
const hotScripts = [
// WebpackDevServer host and port
'webpack-dev-server/client?http://0.0.0.0:8080',
// WebpackDevServer hot reload
'webpack/hot/only-dev-server'
];
const getconfig = function(exportPath) {
if (!exportPath) exportPath = buildPath;
return {
// A SourceMap without column-mappings. SourceMaps from loaders are simplified to a single mapping per line
devtool: "eval",
// cache hotscripts for dev-server.js
hotScripts: hotScripts,
// Cache generated modules and chunks to improve performance for multiple incremental builds
cache: true,
// Enter watch mode (or not), which rebuilds on file change
watch: false,
// The entries point for the bundle
entry: {
"bundle": appScripts
},
// Options affecting the output
output: {
// path of output
path : exportPath,
// [name] is replaced by the name of the chunk
filename: 'scripts/[name].js',
// public path for files serving
publicPath: '/',
},
resolve : {
// An array of extensions that should be used to resolve modules
extensions: ['', '.js', '.jsx', '.scss'],
// Replace modules by other modules or paths
alias : {}
},
// Loaders are transformations that are applied on a resource file of your app
module: {
loaders: [
// babel loader for ES6-7
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loaders: ["babel-loader"],
},
// scss/sass loader with style extraction (ref ExtractTextPlugin)
// width path resolving & source map
{
test: /\.scss$/,
loader: [
"style-loader",
"css-loader",
"sass-loader?sourceMap&includePaths[]=" + modulesPath,
].join("!"),
},
]
},
plugins: [
// Generate an extra chunk, which contains common modules shared between entry points
new webpack.optimize.CommonsChunkPlugin("scripts/init.js"),
// automatically add scripts/styles file to index.html
new HtmlWebpackPlugin({
// Load a custom template
template: path.resolve(buildPath, 'index.html'),
// Inject all scripts into the body
inject: 'body'
})
]
}
};
const config = getconfig();
config.setPath = getconfig;
module.exports = config;