This repository has been archived by the owner on Jan 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
187 lines (158 loc) · 6.21 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const dest = 'build';
const isProd = process.env.NODE_ENV === 'production';
const sassLoaders = [
// @see https://github.com/webpack-contrib/css-loader
{
loader: 'css-loader',
options: {
minimize: isProd
}
},
// @see https://github.com/postcss/postcss-loader
{ loader: 'postcss-loader' },
// @see https://github.com/webpack-contrib/sass-loader
{ loader: 'sass-loader' },
// @see https://github.com/shakacode/sass-resources-loader
// {
// loader: 'sass-resources-loader',
// options: {
// resources: path.resolve(__dirname, 'path/to/_global.scss')
// }
// }
];
module.exports = {
// @see https://webpack.js.org/configuration/entry-context/#entry
entry: './src/main.js',
// @see https://webpack.js.org/configuration/output/
output: {
// The output directory as an absolute path.
path: path.resolve(__dirname, dest),
// This is an important option when using on-demand-loading or loading
// external resources like images, files, etc. If an incorrect value is
// specified you'll receive 404 errors while loading these resources.
//
// This option specifies the public URL of the output directory when
// referenced in a browser. A relative URL is resolved relative to the
// HTML page (or <base> tag). Server-relative URLs, protocol-relative
// URLs or absolute URLs are also possible and sometimes required, i.e.
// when hosting assets on a CDN.
//
// @see https://webpack.js.org/configuration/output/#output-publicpath
publicPath: `./${dest}/`,
// This option determines the name of each output bundle. The bundle is
// written to the directory specified by the output.path option.
//
// @see https://webpack.js.org/configuration/output/#output-filename
filename: 'app.js'
},
// @see https://webpack.js.org/configuration/module/
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
scss: isProd ? ExtractTextPlugin.extract({
use: sassLoaders,
fallback: 'vue-style-loader'
}) : ['vue-style-loader'].concat(sassLoaders)
}
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: [
['env', {
debug: true
}]
]
}
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: path.join('images', '[name].[hash].[ext]')
}
},
{
test: /\.(woff|woff2)$/,
loader: 'file-loader',
options: {
name: path.join('fonts', '[name].[hash].[ext]')
}
},
]
},
// @see https://webpack.js.org/configuration/resolve/
resolve: {
// Create aliases to import or require certain modules more easily.
alias: {
// @see https://github.com/vuejs/vue/tree/dev/dist#runtime--compiler-vs-runtime-only
vue$: 'vue/dist/vue.esm.js'
},
// Automatically resolve certain extensions.
// This defaults to: extensions: [".js", ".json"]
//
// ⚠️ For modules that are imported with their extension, e.g.
// import SomeFile from "./somefile.ext", to be properly resolved,
// a string containing "*" must be included in the array.
extensions: ['*', '.vue', '.js']
},
// @see https://webpack.js.org/configuration/dev-server/
devServer: {
// When using the HTML5 History API, the index.html page will likely
// have to be served in place of any 404 responses.
historyApiFallback: true,
// With noInfo enabled, messages like the webpack bundle information
// that is shown when starting up and after each save, will be hidden.
// Errors and warnings will still be shown.
noInfo: false,
// Tell the server where to serve content from. This is only necessary
// if you want to serve static files.
contentBase: path.resolve(__dirname, './'),
// Enable gzip compression for everything served.
compress: true,
// The bundled files will be available in the browser under this path.
// ⚠️ Make sure publicPath always starts and ends with a forward slash.
// ⚠️ It’s recommended that devServer.publicPath is the same as output.publicPath.
publicPath: `/${dest}/`,
// Add some colors to the output
stats: { colors: true }
},
// @see https://webpack.js.org/configuration/target/
// target: 'web',
// These options allows you to control how webpack notifies you of assets
// and entrypoints that exceed a specific file limit.
//
// @see https://webpack.js.org/configuration/performance/
performance: {
hints: isProd ? 'warning' : false
},
// This option controls if and how source maps are generated.
//
// @see https://webpack.js.org/configuration/devtool/
devtool: isProd ? false : '#cheap-module-source-map',
// @see https://webpack.js.org/configuration/plugins/
plugins: isProd ? [
// @see https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/33
// new UglifyJSPlugin({
// compress: { warnings: false }
// }),
new ExtractTextPlugin({
filename: 'styles.css',
allChunks: true
})
] : [
new FriendlyErrorsPlugin()
]
}