forked from pikock/bootstrap-magic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.prod.js
More file actions
132 lines (129 loc) · 3.95 KB
/
Copy pathwebpack.prod.js
File metadata and controls
132 lines (129 loc) · 3.95 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
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
const path = require('path')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const Dotenv = require('dotenv-webpack')
const srcDir = path.resolve(__dirname, '..', 'scss')
const distDir = path.resolve(__dirname, '..', 'dist')
const { NODE_ENV = 'development' } = process.env
module.exports = {
// Where to fine the source code
context: srcDir,
// No source map for production build
devtool: 'cheap-module-source-map',
entry: ['./index.js'],
output: {
// The destination file name concatenated with hash (generated whenever you change your code).
// The hash is really useful to let the browser knows when it should get a new bundle
// or use the one in cache
filename: 'main.js',
// The destination folder where to put the output bundle
path: distDir,
// Wherever resource (css, js, img) you call <script src="..."></script>,
// or css, or img use this path as the root
publicPath: '/',
// At some point you'll have to debug your code, that's why I'm giving you
// for free a source map file to make your life easier
sourceMapFilename: 'main.map'
},
module: {
rules: [
{
// Webpack, when walking down the tree, whenever you see `.js` file use babel to transpile
// the code to ES5. I don't want you to look into the node_modules folder.
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader'],
include: srcDir
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
minimize: true,
sourceMap: true
}
},
{ loader: 'sass-loader' }
]
})
},
{
test: /\.hbs$/,
loader: 'handlebars-loader',
query: {
partialDirs: [path.join(srcDir, 'templates', 'partials')],
helperDirs: [path.join(srcDir, 'templates', 'helpers')]
}
},
{
test: /\.(eot?.+|svg?.+|ttf?.+|otf?.+|ico?.+|zip?.+|woff?.+|woff2?.+)$/,
use: 'file-loader?name=[path][name].[ext]'
},
{
test: /\.(jpg|jpeg|png|gif|ico)$/,
use: [
// if less than 10Kb, bundle the asset inline, if greater, copy it to the dist/assets
// folder using file-loader
'url-loader?limit=1024&name=[path][name].[ext]'
],
include: path.resolve(srcDir, 'assets')
}
]
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.HashedModuleIdsPlugin(),
// environment globals added must be added to .eslintrc
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(NODE_ENV)
},
NODE_ENV: NODE_ENV,
__DEV__: NODE_ENV === 'development',
__PROD__: NODE_ENV === 'production'
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
screw_ie8: true,
conditionals: true,
unused: true,
comparisons: true,
sequences: true,
dead_code: true,
evaluate: true,
if_return: true,
join_vars: true
},
output: {
comments: false
}
}),
// Put all css code in this file
new ExtractTextPlugin({
filename: '[name].css',
allChunks: true
}),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$|\.eot?.+$|\.ttf?.+$|\.woff?.+$|\.svg?.+$/,
threshold: 10240 // Only assets bigger than this size are processed
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}),
new Dotenv({
path: path.resolve(__dirname, '..', '.env'),
safe: false
})
]
}