-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
125 lines (117 loc) · 4.04 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
const webpack = require('webpack')
const path = require(`path`)
const fs = require('fs')
const chalk = require('chalk')
const mri = require('mri')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { BaseHrefWebpackPlugin } = require('base-href-webpack-plugin');
const env = process.env.NODE_ENV || 'development'
const isDev = env === 'development'
const isProd = env === 'production'
const publishConfig = mri(process.argv.slice(2))['publish-config'] || true
const target = (publishConfig === true) ? env : publishConfig;
const configPath = path.resolve(__dirname, `config/${target}.js`)
if (fs.existsSync(configPath)) {
console.log(chalk.black.bgBlue('INFO') + ' Using ' + chalk.magenta(target) + ' configuration.')
} else {
console.log(chalk.black.bgYellow('WARN') + ' Config file not found for ' + chalk.magenta(target) + ', aborting.')
process.exit()
}
const baseHref = require(configPath).baseHref || '/';
console.log(chalk.black.bgBlue('INFO') + ' baseHref:', baseHref)
const version = require(path.resolve(__dirname, 'package.json')).version
console.log(chalk.black.bgBlue('INFO') + ' version:', version)
module.exports = {
mode: env,
entry: path.join(__dirname, `src`, `main.js`),
output: {
publicPath: isDev ? `/` : baseHref,
},
module: {
rules: [
{
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /node_modules/,
},
{
test: /\.vue$/,
loader: 'vue-loader',
},
// this will apply to both plain `.js` files
// AND `<script>` blocks in `.vue` files
{
test: /\.js$/,
loader: 'babel-loader',
exclude: file => (
/node_modules/.test(file) &&
!/\.vue\.js/.test(file)
)
},
// this will apply to both plain `.css` files
// AND `<style>` blocks in `.vue` files
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader',
],
},
// this will apply to both plain `.scss` files
// AND `<style lang="scss">` blocks in `.vue` files
{
test: /\.scss$/,
use: [
'vue-style-loader',
'css-loader',
{
loader: 'sass-loader',
// options: {
// // you can also read from a file, e.g. `variables.scss`
// data: `$color: red;`
// }
}
]
},
]
},
plugins: [
// make sure to include the plugin!
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
template: 'public/index.html',
favicon: 'public/favicon.ico',
// filename: path.join(__dirname, `dist`, `index.html`),
inject: true,
// minify: minify ? {
// removeComments: true,
// collapseWhitespace: true,
// removeAttributeQuotes: true,
// // More options:
// // https://github.com/kangax/html-minifier#options-quick-reference
// } : false,
}),
new BaseHrefWebpackPlugin({
baseHref
}),
new webpack.DefinePlugin({
VERSION: JSON.stringify(version),
}),
],
devtool: 'inline-source-map',
devServer: {
// prevents Content-Security-Policy header (that blocks links to subroutes)
historyApiFallback: true,
},
resolve: {
alias: {
config$: configPath,
logger$: path.resolve(__dirname, 'src/interfaces/consoleLogger.js'),
}
}
};
if (isProd) {
module.exports.output.filename = '[name].[hash].js'
}