-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.base.js
97 lines (89 loc) · 2.29 KB
/
webpack.config.base.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
/**
* Base webpack config used across other specific configs
*/
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const ROOT_FOLDER = __dirname
const SRC_FOLDER = path.join(ROOT_FOLDER, 'src')
const APP_FOLDER = path.join(ROOT_FOLDER, 'app')
const mainContentPolicy = {
production: "script-src 'self'",
development: "script-src 'self' 'unsafe-eval'",
}
module.exports = {
module: {
rules: [
{
test: /\.jsx?$/,
use: ['babel-loader'],
exclude: /node_modules/
},
{
test: /\.json$/,
loader: 'json-loader',
type: 'javascript/auto'
},
{
test: /\.less$/,
use: [
'style-loader',
'css-loader',
'less-loader'
]
},
{
test: /.*images.+\.svg$/,
loader: 'url-loader',
},
{
test: /.*svg-sprite.+\.svg$/,
loader: 'svg-sprite-loader',
// options: {extract: true}
}
]
},
output: {
path: path.join(__dirname, 'app'),
filename: '[name].js',
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
},
runtimeChunk: {
name: 'manifest',
},
},
// https://webpack.github.io/docs/configuration.html#resolve
resolve: {
alias: {
'ui-framework': path.join(SRC_FOLDER, 'ui-framework'),
'app-utils': path.join(SRC_FOLDER, 'application', 'utils'),
'app-services': path.join(SRC_FOLDER, 'application', 'services'),
'app-images': path.join(SRC_FOLDER, 'images'),
'shared-components': path.join(SRC_FOLDER, 'application', 'shared-components'),
},
extensions: ['.js', '.jsx', '.json'],
mainFields: ['webpack', 'browser', 'web', 'browserify', ['jam', 'main'], 'main']
},
plugins: [
new CleanWebpackPlugin([
path.join('app', 'dist'),
]),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.join(APP_FOLDER, 'main', 'index.html'),
chunks: ['manifest', 'vendors', 'bundle'],
templateParameters: {
contentPolicy: mainContentPolicy[process.env.NODE_ENV]
}
}),
],
}