-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
157 lines (153 loc) · 4.29 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
const path = require('path')
const webpack = require('webpack')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const TypedocWebpackPlugin = require('typedoc-webpack-plugin')
const currentDir = path.resolve('.')
const excludeDirs = [
path.resolve(__dirname, "node_modules"),
path.resolve(__dirname, "node")
]
module.exports = {
entry: {
api: './src/api.ts'
},
output: {
path: path.resolve(__dirname, './dist'),
publicPath: 'dist/',
filename: '[name].js',
chunkFilename: '[name].js'
},
module: {
rules: [{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
// Since sass-loader (weirdly) has SCSS as its default parse mode, we map
// the "scss" and "sass" values for the lang attribute to the right configs here.
// other preprocessors should work out of the box, no loader config like this necessary.
'scss': 'vue-style-loader!css-loader!sass-loader',
'sass': 'vue-style-loader!css-loader!sass-loader?indentedSyntax',
'ts': [
'ts-loader!tslint-loader',
path.resolve('src/scripts/remove-whitespace-ts-loader.js')
]
}
},
include: [ path.resolve(currentDir, 'src') ]
},{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
},
include: [ path.resolve(currentDir, 'src') ]
},{
test: /\.ts$/,
enforce: 'pre',
loader: 'tslint-loader'
},{
test: /\.(jpe?g|png|gif|svg|eot|woff|ttf|svg|woff2)$/,
loader: "file-loader",
},{
test : /\.js$/,
loader: 'babel-loader',
include: [ path.resolve(currentDir, 'src') ]
},{
test: /\.css$/,
loader: 'style-loader'
},{
test: /\.css$/,
loader: 'css-loader'
}]
},
resolve: {
extensions: ['.ts', '.js', '.vue', '.json'],
modules: [ //tell webpack where to search for import
path.resolve(path.resolve('.'), 'src'), //allow importing file without starting by "src/"
path.resolve(currentDir, 'node_modules')
]
},
devServer: {
historyApiFallback: true,
noInfo: true
},
performance: {
hints: false
},
optimization : {
splitChunks: {
cacheGroups: {
vendor: {
test: /node_modules/,
chunks: 'initial',
name: 'vendor',
enforce: true
},
}
}
}
}
if (process.env.NODE_ENV === 'production') {
// production environment
console.log('Webpack will run in production mode')
module.exports.mode = 'production'
module.exports.devtool = '#source-map'
module.exports.resolve.alias = {
'vue': 'vue/dist/vue.min.js',
'vuex': 'vuex/dist/vuex.min.js',
'vuetify-css': 'vuetify/dist/vuetify.min.css'
}
Object.assign(module.exports.optimization, {
minimize: true,
minimizer: [
new UglifyJsPlugin({
sourceMap: true,
uglifyOptions: {
beautify: false,
compress: {
warnings: false
},
comments: false,
mangle: false,
toplevel: false,
keep_classnames: true,
keep_fnames: true,
}
})
]
})
module.exports.plugins = (module.exports.plugins || []).concat([
new TypedocWebpackPlugin({
out: '../doc',
name: 'JMapWeb',
mode: 'modules',
exclude: '**/node_modules/**/*.*',
experimentalDecorators: true,
excludeExternals: true,
includeDeclarations: false,
ignoreCompilerErrors: true,
})
])
} else {
// development environment
console.log('Webpack will run in development mode')
module.exports.mode = 'development'
module.exports.devtool = 'eval'
module.exports.resolve.alias = {
'vue': 'vue/dist/vue.esm.js',
'vuex': 'vuex/dist/vuex.esm.js',
'vuetify-css': 'vuetify/dist/vuetify.css'
}
}
if (process.env.PROCESS_ANALYSER) {
/**
* Used to analyse the size/content of the bundles generated by webpack
* After webpack build a browser tab will open automatically showing the result
* */
console.log('Bundle analyser will be performed, accessible on http://127.0.0.1:8888')
module.exports.plugins = (module.exports.plugins || []).concat([
new BundleAnalyzerPlugin()
])
}