-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
106 lines (103 loc) · 2.8 KB
/
webpack.config.js
File metadata and controls
106 lines (103 loc) · 2.8 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
104
105
106
const settings = require('./settings.js');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const path = require('path');
const autoprefixer = require('autoprefixer');
const del = require('del');
const inlineSassLoader = {
test: /\.scss$/,
loaders: ['style', 'css', 'postcss', 'sass'],
};
const inlineCssLoader = {
test: /\.css$/,
loaders: ['style', 'css', 'postcss'],
};
module.exports = (function createConfig() {
const ENV = process.env.NODE_ENV;
const isProd = ENV === 'prod';
const isDev = ENV === 'dev';
const bootstrapEntryPoint = isProd ? 'bootstrap-loader/extractStyles' : 'bootstrap-loader';
console.log(`Creating webpack config with ENV: ${process.env.NODE_ENV}`);
console.log(`Bootstrap entry-point: ${bootstrapEntryPoint}\n`);
del(['dist/**']).then(paths => {
console.log('Deleted files and folders:\n', paths.join('\n'));
});
const config = {
entry: ['font-awesome-loader', bootstrapEntryPoint, './src/app/index.module.js'],
resolve: {
root: path.resolve(settings.PROJECT_DIR, './src'),
modulesDirectories: ['node_modules'],
},
output: {
path: path.resolve(settings.PROJECT_DIR, './dist'),
filename: 'bundle.[hash].js',
},
module: {
preLoaders: [
{
test: /\.js$/,
loader: 'eslint-loader',
exclude: /node_modules/,
},
],
loaders: [
{
test: /\.js/,
loaders: ['ng-annotate', 'babel'],
exclude: /node_modules/,
},
{
test: /\.html$/,
loader: 'html',
},
{
test: /\.woff2?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url?limit=10000',
},
{
test: /\.(ttf|eot|svg)(\?[\s\S]+)?$/,
loader: 'file',
},
{ test: /bootstrap-sass\/assets\/javascripts\//,
loader: 'imports',
},
],
},
postcss: [autoprefixer],
plugins: settings.WEBPACK_PLUGINS[ENV],
node: {
fs: 'empty',
},
};
if (isProd) {
config.module.loaders.push({
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style',
loader: 'css!postcss!sass',
}),
});
config.module.loaders.push({
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style',
loader: 'css!postcss',
}),
});
} else {
if (isDev) {
config.module.loaders.push(inlineSassLoader);
config.module.loaders.push(inlineCssLoader);
config.devtool = 'inline-source-map';
}
config.entry.unshift(`webpack-dev-server/client?${settings.HOST_LOCATION}`,
'webpack/hot/dev-server');
config.devServer = {
hot: true,
contentBase: '/dist/',
stats: {
colors: true,
},
};
}
return config;
}());