-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.js
139 lines (126 loc) · 3.2 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
import webpack from 'webpack'
import ExtractText from 'extract-text-webpack-plugin'
import pkg from './package.json'
import koutoSwiss from 'kouto-swiss'
import glob from 'glob'
const webpackEnv = process.env.WEBPACK
const NODE_ENV = process.env.NODE_ENV
const isDemo = webpackEnv === 'demo'
const isProd = NODE_ENV === 'production'
const isDev = !webpackEnv && !isProd && !isDemo
const conf = {
isDemo, isProd, isDev,
cssLocalIdentName: '[name]-[local]-[hash:base64:5]',
publicPath: '//localhost:3001/',
...require('./src/conf'),
}
const __icons = glob.sync('assets/icons/*.svg').map(icon => {
return icon.replace(/^assets\/icons\//, '')
.replace(/(^icon-)|(\.svg$)/g, '')
})
module.exports = {
...conf,
__icons,
entry: {
[conf.repoName]: !isProd
? ['./src/demo/client'].concat(isDemo ? [] : [`webpack-hot-middleware/client?path=${conf.publicPath}__webpack_hmr`])
: './src/components'
},
output: {
path: isProd ? `${__dirname}/build/dist` : isDemo ? `${__dirname}/demo/${conf.repoName}` : `${__dirname}/static`,
filename: isDemo ? 'demo.js' : '[name].js',
library: 'OWLUI',
libraryTarget: 'umd',
publicPath: conf.publicPath
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: isDev ? ['react-hmre'] : []
}
},
{
test: /\.raw$/,
loader: 'raw',
},
{
test: /\.json$/,
loader: 'json'
},
{
test: /\.styl$/,
loader: isDev ?
'style!' +
`css?sourceMap&modules&localIdentName=${conf.cssLocalIdentName}!` +
'stylus' :
ExtractText.extract('style', [
`css?modules&localIdentName=[hash:base64:11]`,
'stylus'
])
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'url?limit=100000'
},
{
test: /\.css$/,
loader: 'style!css'
},
]
},
resolve: {
alias: isDemo ? {
'react': 'react/dist/react.min.js',
'react-dom': 'react-dom/dist/react-dom.min.js',
'react-redux': 'react-redux/dist/react-redux.min.js',
'redux': 'redux/dist/redux.min.js',
'redux-thunk': 'redux-thunk/dist/redux-thunk.min.js',
} : {}
},
stylus: {
use: [koutoSwiss()],
paths: [`${__dirname}/node_modules`],
import: `${__dirname}/src/stylus/variables.styl`
},
plugins: [
new webpack.DefinePlugin({
__icons: JSON.stringify(__icons),
__isNode: false,
__isDev: isDev,
})
].concat(isDev
?
[
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
]
:
[
new ExtractText( isDemo ? 'demo.css' : 'owl-ui.css'),
]
),
watch: isDev,
devtool: isDev ? 'eval' : '',
externals: isProd ? {
...Object.keys(pkg.dependencies).reduce((o, dep) => {
o[dep] = true
return o
}, {}),
react: {
root: 'React',
commonjs: 'react',
commonjs2: 'react',
amd: 'react',
},
'react-dom': {
root: 'ReactDOM',
commonjs: 'react-dom',
commonjs2: 'react-dom',
amd: 'react-dom',
}
} : {}
}