-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
221 lines (193 loc) · 5.17 KB
/
Copy pathwebpack.config.js
File metadata and controls
221 lines (193 loc) · 5.17 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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/**
* Webpack Configuration
*/
// Third-party dependencies
const PATH = require('path');
const CHALK = require('chalk');
const WEBPACK = require('webpack');
const EXTRACT_TEXT = require('extract-text-webpack-plugin');
const PROGRESS_BAR = require('progress-bar-webpack-plugin');
const UGLIFYJS = require('uglifyjs-webpack-plugin');
// Environment variables
const APP = './static';
const VENDOR = './node_modules';
const ENTRY = './source/entry.js';
const IS_PRODUCTION = ( process.env.NODE_ENV === 'production' ) ? true : false;
let webpackConfig = (function(){
/**
* Configuration object
*/
let config = {};
/**
* Entry Point - JS root file
* @see https://webpack.js.org/configuration/entry-context/
*/
config.entry = PATH.resolve( __dirname, ENTRY );
/**
* Output - Compiled JS file (referenced in HTML)
* @see https://webpack.js.org/configuration/output/
*/
config.output = {
path: PATH.resolve( __dirname, APP ),
publicPath: APP + '/',
filename: 'script.js',
};
/**
* Module Transformations - Rules for how to preprocess files into modules
* @see https://webpack.js.org/configuration/module/
*/
config.module = {
rules: [
{
/**
* Script Transformations - Output ES/TS to JS files
*/
test: /\.js$|\.es$|\.ts$/,
use: [
{
/**
* Babel - Compiles next-gen JavaScript (ES6+) to browser-compatible JS
* @see https://babeljs.io/docs/setup/#installation
*/
loader: 'babel-loader',
query: {
presets: ['env', 'es2015-node6', 'stage-2']
}
},
{
/**
* ESLint - The pluggable linting utility for JavaScript and JSX
* @see https://github.com/MoOx/eslint-loader
*/
loader: 'eslint-loader',
options: {
baseConfig: {
extends: [
'eslint:recommended'
]
},
parser: 'babel-eslint',
envs: [
'browser',
'es6',
'node'
],
rules: {
strict: 0,
quotes: [
2,
'single'
],
'no-unused-vars': 1,
'no-console': 0
}
}
}
]
},
{
/**
* Style Transformations - Output SASS/SCSS to CSS files
*/
test: /\.css$|\.sass$|\.scss$/,
use: EXTRACT_TEXT.extract({
use: [
{
/**
* CSS Loader - Transpiles CSS into CommonJS (for Webpack)
* @see https://github.com/webpack-contrib/css-loader
*/
loader: 'css-loader',
options: {
importLoaders: 2,
url: false,
minimize: IS_PRODUCTION // Uses cssnano
}
},
{
/**
* PostCSS - CSS transformations via JS Plugins
* @see ./postcss.config.js for settings
* @see https://github.com/postcss/postcss-loader
*/
loader: 'postcss-loader'
},
{
/**
* Sass - Compile Sass to CSS using node-sass
* @see https://github.com/webpack-contrib/sass-loader
*/
loader: 'sass-loader',
options: {
outputStyle: 'expanded',
includePaths: [ ]
}
}
],
fallback: {
/**
* Style Loader - Adds CSS to the DOM by injecting a <style> tag
* @see https://github.com/webpack-contrib/style-loader
*/
loader: 'style-loader'
}
})
}
]
};
/**
* Resolve - Include paths & options for resolving dependencies
* @see https://webpack.js.org/configuration/resolve/
*/
config.resolve = {
modules: [
PATH.resolve( VENDOR )
],
alias: {
'vue': 'vue/dist/vue.min.js'
}
};
/**
* Plugins - Customize build process
* @see https://webpack.js.org/configuration/plugins/
*/
config.plugins = [
new EXTRACT_TEXT({
filename: 'style.css',
allChunks: true
}),
new PROGRESS_BAR({
format: ' build [:bar] ' + CHALK.green.bold(':percent') + ' (:elapsed seconds)',
clear: false
})
];
/**
* Externals - Dependencies excluded from build process (globals)
* @see https://webpack.js.org/configuration/externals/#externals
*/
config.externals = {};
/**
* Profiler stats during compilation
*/
config.stats = {
colors: true,
errors: true,
errorDetails: true,
cached: true
};
/**
* Production conditions
*/
if (IS_PRODUCTION) {
config.plugins.push(new UGLIFYJS());
config.plugins.push(
new WEBPACK.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
})
)
}
return config;
})();
module.exports = webpackConfig;