-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.base.js
More file actions
170 lines (157 loc) · 4.87 KB
/
webpack.config.base.js
File metadata and controls
170 lines (157 loc) · 4.87 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
/*eslint-disable */
const NODE_ENV = process.env.NODE_ENV || 'development',
webpack = require('webpack'),
ExtractTextPlugin = require('extract-text-webpack-plugin'),
extractSASS = new ExtractTextPlugin('./css/[name].css'),
extractCSS = new ExtractTextPlugin('./css/[name].css'),
OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'),
CopyWebpackPlugin = require('copy-webpack-plugin')
const needToWatchChanges = NODE_ENV !== 'production' && NODE_ENV !== 'demo'
const codeCompression = NODE_ENV === 'production' || NODE_ENV === 'demo'
const mode = NODE_ENV === 'production' && 'production' || 'development'
const path = require('path')
// минимизируем css для production
// const CSS_LOADER_NAME = (NODE_ENV === 'production') ? 'css?minimize' : 'css?-minimize';
module.exports = {
mode,
watch: needToWatchChanges,
watchOptions: {
aggregateTimeout: 100,
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
NODE_ENV: JSON.stringify(NODE_ENV),
}),
extractCSS,
extractSASS,
new CopyWebpackPlugin([
{ from: './static' }
])
],
resolve: {
modules: [
path.join(__dirname, 'src'),
'node_modules',
],
extensions: ['.js', '.jsx'],
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(static|node_modules|bower_components)/,
loader: 'babel-loader',
},
{
test: /thp\/*\.(js)$/,
exclude: /(node_modules|bower_components)/,
loader: 'raw-loader'
},
{
test: /\.mst$/,
use: [
{
loader: 'mustache-loader',
options: {
noShortcut: true,
},
}
],
},
{
test: /\.pug$/,
use: [
{
loader: 'pug-loader',
options: {},
}
],
},
{
test: /\.css$/,
loader: extractCSS.extract({ use: ['css-loader', 'style-loader'] }),
},
{
test: /\.scss$/,
loader: extractSASS.extract({ fallback: 'style-loader', use: ['css-loader', 'sass-loader'] }),
},
{
test: /\.(png|jpg)$/,
// options.name указывает путь, куда будут скопированы файлы, путь относительно output.path конфигурации webpack,
// помимо этого, этот параметр задает строку замены пути в файлах css
// options.regExp задает регулярное выражение по которому будут подбираться файлы, анализ параметра url
// options.limit задает лимит размера файлов, которые могут быть вставлены как Base64 строка, если размер файла будет превышать это
// значение он будет скопирован в директорию
loader: 'url-loader',
options: {
name: '../img/[name].[ext]',
regExp: 'Resources/img/(.*)',
limit: '1248',
},
},
{
test: /\.svg/,
use: [
// {
// loader: 'svg-url-loader',
// options: {
// name: '../img/[name].[ext]',
// regExp: 'resources/img/(.*)',
// limit: '1248',
// },
// },
{
loader: 'raw-loader'
}]
}
],
},
// модули и из настройки для загрузчика postcss
// postcss: function () {
// return [
// // автоматически проставит вендорные префиксы
// autoprefixer({
// browsers: browserslist('ie < 12, Opera < 20, Firefox < 20, Chrome < 40, Edge < 15')
// })
// // препроцессор ()
// // , require('precss')
// ];
// }
}
if (codeCompression) {
// плагин сжатия js исходников
module.exports.plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
drop_console: true,
unsafe: true,
screw_ie8: false,
},
mangle: {
screw_ie8: false,
except: ['name', 'super', '$super', '$uper'],
},
mangleProperties: {
screw_ie8: false,
except: ['name', 'super', '$super', '$uper'],
},
output: {
screw_ie8: false,
},
}))
// добавляем плагин сжатия css файлов
module.exports.plugins.push(new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.min\.css$/,
cssProcessorOptions: {
discardComments: {
removeAll: true,
},
},
}))
}
/*
conversation about ie8 capability https://phabricator.babeljs.io/T2817
*/
/*eslint-enable */