This repository has been archived by the owner on Jul 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
80 lines (74 loc) · 2.4 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
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const resolve = file => path.resolve(__dirname, file)
const { lstatSync, readdirSync } = require('fs')
const webpack = require('webpack')
const path = require('path')
const isDirectory = o => lstatSync(o.path).isDirectory()
const getDirectories = source => {
return readdirSync(source)
.map(name => ({ path: path.join(source, name), name }))
.filter(isDirectory)
}
const nodeExternals = require('webpack-node-externals')
const configs = getDirectories(resolve('src')).map(o => {
// Get path to first .vue template in directory
const componentPath =
o.path +
'/' +
readdirSync(o.path)
.filter(f => f.includes('.vue'))
.shift()
const config = {
entry: componentPath,
externals: [nodeExternals()],
output: {
filename: `${o.name}.js`,
library: 'fh-components',
libraryTarget: 'umd',
libraryExport: 'default'
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
scss: 'vue-style-loader!css-loader!sass-loader'
},
extractCSS: false,
preserveWhitespace: false,
postcss: [
require('autoprefixer')({
browsers: ['last 5 versions']
})
]
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.svg$/,
loader: 'svg-inline-loader?removeSVGTagAttrs=false'
},
{
test: /\.(png|woff|woff2|eot|ttf)$/,
loader: 'url-loader',
options: {
limit: 10000,
name: '[name].[ext]?[hash]'
}
},
{
test: /\.css$/,
use: 'vue-style-loader'
}
]
}
}
return config
})
module.exports = configs