-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathwebpack.config.js
105 lines (100 loc) · 2.57 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
'use strict';
const path = require('path');
const chalk = require('chalk');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const SRC_DIR = path.join(__dirname, 'src');
const PUBLIC_DIR = path.join(__dirname, 'public');
const DIST_DIR = path.join(__dirname, 'dist');
const PORT = 3001;
module.exports = () => ({
entry: ['@babel/polyfill', path.join(SRC_DIR, 'index.tsx')],
output: {
path: DIST_DIR,
filename: 'app.js',
publicPath: '/',
},
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader',
},
{
test: /\.tsx$/,
loader: 'babel-loader!ts-loader',
},
{
test: /\.scss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
camelCase: true,
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]',
},
},
{
loader: 'sass-loader',
options: {
implementation: require('sass'),
data: `@import "abstracts";`,
includePaths: [path.resolve(__dirname, 'src/style')],
},
},
],
},
{
test: /\.(png|woff|woff2|eot|ttf)$/,
loader: 'url-loader',
},
],
},
devServer: {
before() {
console.clear();
},
contentBase: SRC_DIR,
historyApiFallback: true,
host: '0.0.0.0',
port: PORT,
public: `localhost:${PORT}`,
publicPath: '/',
quiet: true,
},
plugins: [
new CopyWebpackPlugin([
{
from: path.join(PUBLIC_DIR, 'img'),
to: 'img',
toType: 'dir',
},
]),
new FriendlyErrorsWebpackPlugin({
compilationSuccessInfo: {
messages: [`The demo is accessible at ${chalk.blue(`http://localhost:${PORT}`)}`],
notes: [
`Note that the development build is not optimized`,
`To create a production build, use ${chalk.blue('npm run build')}.`,
],
},
}),
new HtmlWebpackPlugin({
template: path.join(PUBLIC_DIR, 'index.html'),
favicon: path.join(PUBLIC_DIR, 'favicon.ico'),
}),
],
resolve: {
extensions: ['.ts', '.tsx', '.js'],
modules: [path.join(__dirname, 'node_modules')],
plugins: [
new TsconfigPathsPlugin({
configFile: './tsconfig.json',
}),
],
},
});