forked from dutchorka/Pluff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
123 lines (116 loc) · 3.36 KB
/
webpack.config.babel.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import path from 'path';
import webpack from 'webpack';
import HtmlWebPackPlugin from 'html-webpack-plugin';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import autoprefixer from 'autoprefixer';
import { execSync } from 'child_process';
import dotenv from 'dotenv';
dotenv.config({ silent: true });
const IS_DEBUG = process.env.PLUFF_DEBUG === 'true';
console.log(`Building for ${IS_DEBUG ? 'DEVELOPMENT' : 'production'}!`);
// Get the current git commit hash.
const commitHash = execSync('git rev-parse --short HEAD', { encoding: 'utf8' }).trim();
// Plugins that are used for all environments.
const plugins = [
// Prevent including all locales of moment.
new webpack.IgnorePlugin(/^\.\/locale$/, [/moment$/]),
// Main static file.
new HtmlWebPackPlugin({
inject: 'head',
template: 'app/index.htm',
// Relative to `output.publicPath`.
filename: '../index.html',
commitHash,
}),
new ExtractTextPlugin('[name]-[contenthash:7].css', {
allChunks: true,
}),
// Define globals that get inserted in plugin.
new webpack.DefinePlugin({
__DEV__: IS_DEBUG,
}),
];
if (!IS_DEBUG) {
plugins.push(new webpack.optimize.DedupePlugin());
plugins.push(new webpack.optimize.UglifyJsPlugin({
// UglifyJs produces nonsense warnings by default.
compress: { warnings: false },
// Mangling fucks up Angular.
mangle: false,
}));
plugins.push(new webpack.optimize.OccurenceOrderPlugin());
}
export default {
context: __dirname,
entry: {
bundle: 'boot.js',
},
devtool: IS_DEBUG ? '#eval' : null,
debug: IS_DEBUG,
output: {
filename: '[name]-[hash:7].js',
chunkFilename: '[name]-[id]-[chunkhash:7].js',
path: path.join(__dirname, 'dist/static'),
publicPath: 'static/',
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
}, {
// Nasty hack to work around a bug in html-webpack-plugin / extract-text-webpack-plugin,
// where the output is wrong if you're using an inline loader.
test: /\.htm$/,
loader: 'underscore-template-loader',
query: {
// html attributes that should be parsed as module.
attributes: ['img:src', 'link:href'],
},
}, {
test: /\.html$/,
loader: 'raw',
}, {
test: /\.scss$/,
// First compile with Sass and then Postcss.
loader: ExtractTextPlugin.extract(
'css?sourceMap!' +
'postcss!' +
'sass?sourceMap&outputStyle=compressed',
// Paths in CSS are relative to dist/static/ instead of dist/
{ publicPath: '' }
),
}, {
test: /\.json$/,
loader: 'json',
}, {
// Extract all non-CSS and non-JS assets.
test: /\.(gif|png|jpe?g|svg|ico|woff|ttf)$/i,
loader: 'file',
query: {
name: '[name]-[hash:7].[ext]',
},
},
],
},
plugins,
resolveLoader: {
root: path.join(__dirname, 'node_modules'),
},
resolve: {
root: path.join(__dirname, 'app'),
extensions: ['', '.js'],
alias: {
'angular-translate-cookie': 'angular-translate/dist/angular-translate-storage-cookie/angular-translate-storage-cookie',
},
},
postcss() {
return [
autoprefixer({ browsers: ['last 1 versions'] }),
];
},
devServer: {
historyApiFallback: true,
},
};