forked from nickjj/build-a-saas-app-with-flask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
166 lines (145 loc) · 5.31 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
var fs = require('fs');
var path = require('path');
// Webpack and third party plugins.
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var AutoPrefixerPlugin = require('autoprefixer-core');
var ManifestRevisionPlugin = require('manifest-revision-webpack-plugin');
// Environment detection.
var node_env = process.env.NODE_ENV || 'development';
/*
Configuration settings
------------------------------------------------------------------------------
*/
// Where is your project located relative to this config?
var context = path.join(__dirname, '..');
// Where are your source assets located?
var rootAssetPath = './catwatch/assets';
var contextRoot = path.join(context, rootAssetPath);
// Which human languages do you want to support? (regex)
var languages = /en|es/;
// Where will the files get built to?
var buildOutputPath = './build/public';
// How should certain asset types be configured?
var assets = {
fonts: {
path: 'fonts',
filename: '[path][name].[hash].[ext]'
},
images: {
path: 'images',
filename: '[path][name].[hash].[ext]'
},
scripts: {
path: 'scripts',
filename: '[name].[chunkhash].js',
chunkFilename: '[id].[chunkhash].js'
},
styles: {
path: 'styles',
filename: '[name].[chunkhash].css'
}
};
// Which top level JS and CSS files should get output?
var chunks = {
app_js: [
path.join(contextRoot, assets.scripts.path, 'entry.js')
],
app_css: [
path.join(contextRoot, assets.styles.path, 'default.scss')
],
vendor_js: ['bootstrap-sass', 'moment', 'rome'],
vendor_css: [
// Bootstrap configuration settings:
// https://gist.github.com/anonymous/ef4593b01915d647ed88
// http://getbootstrap.com/customize/?id=ef4593b01915d647ed88
path.join(contextRoot, assets.styles.path,
'vendor', 'bootstrap.3.3.5.min.css'),
path.join(contextRoot, assets.styles.path,
'vendor', 'font-awesome.4.3.0.css'),
path.join(contextRoot, assets.styles.path,
'vendor', 'rome.2.1.17.css')
]
};
// Avoid parsing this code to speed up rebuilds.
var noParse = [
path.join(contextRoot, assets.styles.path, 'vendor')
];
// Where will assets get served in development mode? This depends on running
// the webpack dev server.
var publicPath = process.env.PUBLIC_PATH || 'http://localhost:2992/assets/';
/*
Do not edit past this line unless you are tinkering with webpack.
------------------------------------------------------------------------------
*/
// Plugins that will load in all environments.
var plugins = [
// http://webpack.github.io/docs/list-of-plugins.html#noerrorsplugin
new webpack.NoErrorsPlugin(),
// http://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
new webpack.optimize.CommonsChunkPlugin('vendor_js', 'vendor_js.js'),
// https://github.com/webpack/extract-text-webpack-plugin
new ExtractTextPlugin(assets.styles.filename),
// http://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, languages),
// https://github.com/nickjj/manifest-revision-webpack-plugin
new ManifestRevisionPlugin(path.join('build', 'manifest.json'), {
rootAssetPath: rootAssetPath,
ignorePaths: ['/fonts', '/styles', '/scripts']
})
];
// Development environment only plugins.
if (node_env !== 'development') {
var developmentPlugins = [
// http://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
new webpack.optimize.UglifyJsPlugin({compressor: {warnings: false}}),
// http://webpack.github.io/docs/list-of-plugins.html#dedupeplugin
new webpack.optimize.DedupePlugin()
];
plugins.push(developmentPlugins[0])
}
module.exports = {
context: path.join(__dirname, '../'),
entry: chunks,
output: {
path: buildOutputPath,
publicPath: publicPath,
filename: assets.scripts.filename,
chunkFilename: assets.scripts.chunkFilename
},
resolve: {
// Allow requiring files without supplying the extension.
extensions: ['', '.js', '.scss']
},
module: {
noParse: noParse,
loaders: [
{
test: /\.js$/i, loader: 'babel-loader?stage=0',
exclude: /node_modules/
},
{
test: /\.s?css$/i,
loader: ExtractTextPlugin.extract('style-loader',
'css-loader!postcss-loader!sass-loader?includePaths[]=' + path.join(contextRoot, assets.styles.path))
},
{
test: /\.(jpe?g|png|gif|svg([\?]?.*))$/i,
loaders: [
'file?context=' + rootAssetPath + '&name=' + assets.images.filename,
'image?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
},
{
test: /\.(woff([\?]?.*)|woff2([\?]?.*))$/i,
loader: 'url-loader?limit=100000'
},
{
test: /\.(ttf([\?]?.*)|eot([\?]?.*))$/i,
loader: 'file-loader?context=' + rootAssetPath + '&name=' + assets.fonts.filename
}
]
},
plugins: plugins,
postcss: [AutoPrefixerPlugin()]
};