forked from emakina-cee-oss/babel-7-typescript-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.base.js
106 lines (102 loc) · 2.62 KB
/
webpack.config.base.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
const path = require('path')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const packageJson = require('./package.json')
const vendorDependencies = Object.keys(packageJson['dependencies'])
const threadLoader = {
loader: 'thread-loader',
options: {
// there should be 1 cpu for the fork-ts-checker-webpack-plugin
workers: require('os').cpus().length - 1
}
}
const babelLoader = {
loader: 'babel-loader',
options: {
cacheDirectory: true,
}
}
module.exports = {
cache: true,
entry: {
main: './src/index.tsx',
vendor: vendorDependencies
},
optimization: {
},
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].js',
chunkFilename: '[chunkhash].js',
publicPath: '/',
},
module: {
rules: [
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
{ loader: 'cache-loader' },
threadLoader,
babelLoader
]
},
{
test: /\.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
loader: 'file-loader?name=build/[path][name].[ext]',
exclude: /images/
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loader: 'file-loader?name=build/[path][name].[ext]',
include: /images/
},
{
test: /\.scss$/,
use: [{
loader: require.resolve('style-loader')
},
{
loader: require.resolve('css-loader'),
options: {
sourceMap: true
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: true
}
},
{
// Webpack expects all url(...) paths in SASS files to be found relative to the root.scss file we import in our react components,
// but the paths we use are relative to the .scss file that contains the url(...) line. This loader will update the urls to match
// webpack's expectations.
loader: require.resolve('resolve-url-loader'),
options: {
sourceMap: true
}
},
{
loader: require.resolve('sass-loader'),
options: {
sourceMap: true
}
}]
}
]
},
plugins: [
new ForkTsCheckerWebpackPlugin({
checkSyntacticErrors: true,
tslint: true,
watch: ['./src'] // optional but improves performance (less stat calls)
}),
new HtmlWebpackPlugin({
title: 'Webpack demo'
})
],
resolve: {
extensions: ['.webpack.js', '.ts', '.tsx', '.js', '.jsx', '.json', 'scss']
}
}