This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
63 lines (59 loc) · 2.18 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
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var GitRevisionPlugin = require('git-revision-webpack-plugin');
var WebpackShellPlugin = require('webpack-shell-plugin');
var pkg = require('./package.json');
var gitPlugin = new GitRevisionPlugin();
var bundleCss = ('production' === process.env.NODE_ENV) ? 'css/main-[hash:6].css' : 'css/main.css';
var pluginsWebpack = [
new ExtractTextPlugin(bundleCss),
new HtmlWebpackPlugin({
filename: '../templates/index.html',
template: 'shadowcraft_ui/templates/webpack-index.ejs',
cache: true,
inject: false
}),
new webpack.DefinePlugin({
__COMMIT_HASH__: JSON.stringify(gitPlugin.version())
})
];
if ('production' === process.env.NODE_ENV) {
var prodEnv = [
// This will rm anything except the last four bundles and CSS builds so that we
// don't fill up the disk full of crap.
new WebpackShellPlugin({
onBuildStart: ['find shadowcraft_ui/static -name "bundle-*.js" -printf "%Ts\t%p\n" | sort -nr | cut -f2 | tail -n +5 | xargs rm -f',
'find shadowcraft_ui/static/css -name "main-*.css" -printf "%Ts\t%p\n" | sort -nr | cut -f2 | tail -n +5 | xargs rm -f'],
safe: true
})
];
pluginsWebpack.concat(pluginsWebpack, prodEnv);
}
module.exports = {
entry: './shadowcraft_ui/js/app.js',
output: {
path: __dirname + '/shadowcraft_ui/static',
filename: ('production' === process.env.NODE_ENV) ? 'bundle-[hash:6].js' : 'bundle.js'
},
devtool: ('production' == process.env.NODE_ENV) ? '' : 'inline-source-map',
module: {
rules: [
{
test: /\.js?$/,
use: [{
loader: 'babel-loader'
}],
exclude: /node_modules/
},
{
test: /\.sass$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
}
]
},
plugins: pluginsWebpack
};