-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
98 lines (91 loc) · 2.28 KB
/
webpack.config.ts
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
const path = require('path');
const _ = require('lodash')
const webpack = require('webpack')
const { TsConfigPathsPlugin, CheckerPlugin } = require('awesome-typescript-loader')
const TypedocWebpackPlugin = require('typedoc-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const env = process && process.env && process.env.NODE_ENV
const serverPort = process.env.npm_package_config_devPort || 8081
const dev = !(env && env === 'production')
/**
* Update this variable if you change your library name
*/
const title = 'Fragworks';
const libraryName = 'app';
const plugins = [
new CheckerPlugin(),
new TsConfigPathsPlugin(),
new HtmlWebpackPlugin({
inject: true,
title,
filename: 'index.html',
template: path.join(__dirname, 'index.html'),
hash: true,
chunks: [ 'common', 'index' ]
}),
new CopyWebpackPlugin([
{ from: 'views', to: 'views' },
{ from: 'vendor', to: 'vendor' }
])
]
let entry: string | string[] = [
// 'react-hot-loader/patch',
`webpack-dev-server/client?http://localhost:${serverPort}`,
// bundle the client for webpack-dev-servers and connect to the provided endpoint
'webpack/hot/only-dev-server',
// bundle the client for hot reloading
`./src/${libraryName}.ts`
]
if (dev === false) {
plugins.push(new TypedocWebpackPlugin(
{
theme: 'minimal',
out: 'docs',
target: 'es6',
ignoreCompilerErrors: true
},
'src'
))
entry = path.join(__dirname, `src/${libraryName}.ts`)
} else {
plugins.push(new webpack.HotModuleReplacementPlugin())
}
const tsRule = {
test: /\.ts$/,
loader: 'awesome-typescript-loader'
};
const sassRule = {
test: /\.scss/,
loader: [ 'style-loader', 'css-loader?sourceMap', 'sass-loader?sourceMap' ]
};
const rules = [
tsRule,
sassRule
];
export default {
entry: {
index: entry
},
// Currently cheap-module-source-map is broken https://github.com/webpack/webpack/issues/4176
devtool: 'source-map',
output: {
path: path.join(__dirname, 'dist'),
libraryTarget: 'umd',
library: _.camelCase(libraryName),
filename: `${libraryName}.js`
},
resolve: {
extensions: [ '.ts', '.js', '.scss' ]
},
module: {
rules
},
plugins,
devServer: {
hot: true,
contentBase: path.resolve(__dirname, 'dist'),
port: serverPort,
publicPath: '/'
}
}