This repository was archived by the owner on Apr 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
72 lines (69 loc) · 1.83 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
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const resolve = v => path.resolve(__dirname, v)
const isDevelopment = process.env.NODE_ENV === 'development'
const isDocBuild = !!process.env.DOC_ENV
let plugins = [
new ExtractTextPlugin('index.css'),
new CleanWebpackPlugin([isDevelopment ? 'docs' : 'dist']),
]
const appEntry = isDevelopment ? {app: resolve('example/test.js')} : {}
if (isDevelopment) {
plugins = plugins.concat([
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'example/index.html',
chunks: ['index', 'app']
})
])
} else plugins.push(new UglifyJSPlugin())
module.exports = {
entry: {
index: resolve('src/index.ts'),
...appEntry
},
devtool: isDevelopment && 'source-map',
module: {
rules: [
{
test: /\.ts?$/,
use: [{
loader: 'babel-loader',
options: {
presets: [['env', {
targets: {'browsers': ['last 2 versions', 'safari >= 7']}
}]],
plugins: [
'add-module-exports'
]
}
}, 'ts-loader'],
exclude: /node_modules/
},
{
test: /\.styl$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'stylus-loader']
})
}
],
},
devServer: {
contentBase: './docs'
},
resolve: {
extensions: [ '.ts', '.js', '.styl' ]
},
output: {
filename: '[name].js',
path: isDevelopment ? resolve('docs') : resolve('dist'),
library: 'GhTalk',
libraryTarget: 'var',
publicPath: isDocBuild ? './' : '/'
},
plugins
}