-
Notifications
You must be signed in to change notification settings - Fork 124
/
build.config.js
38 lines (33 loc) · 1.13 KB
/
build.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
const webpack = require.main.require('webpack')
const {name, version} = require('./package.json')
const demo = process.env.NODE_ENV === 'development' || process.env.npm_lifecycle_event === 'dist:demo'
module.exports = {
// generate html only for dev and dist:demo
html: demo,
webpack: {
devtool: false, // disable source-map
output: {
publicPath: '.', // generate client.*.js relative to ./demo/index.html
filename: demo ? undefined : kebabCase(name) + '.js', // my-component.js
library: demo ? undefined : camelCase(name) // MyComponent
},
plugins: [
new webpack.DefinePlugin({
'proccess.env.VERSION': JSON.stringify(version) // adds MyComponent.version
})
]
}
}
// utils
// converts MyComponent to my-component
function kebabCase (s) {
return s.replace(/([A-Z])([^A-Z\-])/g, (_, a, b) => `-${a}${b}`)
.toLowerCase()
.replace(/[\s_-]+/g, '-')
.replace(/(^\W)|(\W$)/g, '')
}
// converts my-component to MyComponent
function camelCase (s) {
return s.replace(/([\-_\s]+[a-z])|(^[a-z])/g, $1 => $1.toUpperCase())
.replace(/[\-_\s]+/g, '')
}