-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathmakewebpackconfig.js
More file actions
103 lines (100 loc) · 3.71 KB
/
makewebpackconfig.js
File metadata and controls
103 lines (100 loc) · 3.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
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var WebpackDevServer = require('webpack-dev-server');
module.exports = function(options) {
var entry;
var cssLoaders;
var plugins;
if (options.prod) {
entry = [
path.resolve(__dirname, 'src/app.js') // Start with js/app.js...
];
cssLoaders = 'style-loader!css-loader!postcss-loader';
plugins = [
new webpack.optimize.UglifyJsPlugin({ // Optimize the JavaScript...
compress: {
warnings: false // ...but do not show warnings in the console (there is a lot of them)
}
}),
new HtmlWebpackPlugin({
template: 'src/index.html', // Move the index.html file...
favicon: 'src/assets/img/favicon.ico',
minify: { // Minifying it while it is parsed
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true
},
inject: true // inject all files that are generated by webpack, e.g. bundle.js, main.css with the correct HTML tags
}),
new ExtractTextPlugin("css/main.css"),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
})
];
} else {
entry = [
"webpack-dev-server/client?http://localhost:3000", // Needed for hot reloading
"webpack/hot/only-dev-server", // See above
path.resolve(__dirname, 'src/app.js') // Start with js/app.js...
];
cssLoaders = 'style-loader!css-loader!postcss-loader';
plugins = [
new webpack.HotModuleReplacementPlugin(), // Make hot loading work
new HtmlWebpackPlugin({
favicon: 'src/assets/img/favicon.ico',
template: 'src/index.html', // Move the index.html file
inject: true // inject all files that are generated by webpack, e.g. bundle.js, main.css with the correct HTML tags
})
];
}
return {
entry: entry,
output: { // Compile into js/build.js
path: path.resolve(__dirname, 'build'),
filename: 'js/bundle.js'
},
module: {
loaders: [{
test: /\.js$/, // Transform all .js files required somewhere within an entry point...
loader: 'babel', // ...with the specified loaders...
exclude: path.join(__dirname, '/node_modules/') // ...except for the node_modules folder.
}, {
test: /\.css$/, // Transform all .css files required somewhere within an entry point...
loader: cssLoaders // ...with PostCSS
}, {
test: /\.jpe?g$|\.gif$|\.png$|\.woff2|\.woff|\.ttf/i,
loader: "url-loader?limit=10000"
}
]
},
plugins: plugins,
postcss: function() {
return [
require('postcss-import')({ // Import all the css files...
glob: true,
onImport: function (files) {
files.forEach(this.addDependency); // ...and add dependecies from the main.css files to the other css files...
}.bind(this) // ...so they get hot–reloaded when something changes...
}),
require('postcss-simple-vars')(), // ...then replace the variables...
require('postcss-reporter')({ // This plugin makes sure we get warnings in the console
clearMessages: true
})
];
},
target: 'web', // Make web variables accessible to webpack, e.g. window
stats: false, // Don't show stats in the console
progress: true,
};
}