-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.js
149 lines (141 loc) · 3.97 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
140
141
142
143
144
145
146
147
148
149
const webpack = require('webpack')
const Clean = require('clean-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin')
const AutoDllPlugin = require('autodll-webpack-plugin')
const OfflinePlugin = require('offline-plugin');
// const cssModules = require('./tools/webpack-blocks/css-loader')
const path = require('path')
const __DEV__ = process.env.NODE_ENV === 'development'
const Dist = `${__dirname}/static/dist/`
const Name = 'inker'
module.exports = {
mode: process.env.NODE_ENV,
entry: {
bundle: "./src/index.js",
},
output: {
filename: "[name]_[hash:5].js",
path: Dist,
publicPath: `/${Name}/static/dist/`,
},
// Enable sourcemaps for debugging webpack's output.
devtool: "source-map",
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".ts", ".tsx", ".js", ".json"],
modules: ['node_modules', 'src'],
},
devServer: {
host: '0.0.0.0',
contentBase: './',
hot: true,
proxy: {
}
},
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.tsx?$/,
use: [{
loader: "awesome-typescript-loader",
options: {
useTranspileModule: true,
transpileOnly: true,
declaration: false,
instance: 'at-loader2'
}
}, {
loader: './tools/minify-cssinjs-loader',
}, {
loader: "awesome-typescript-loader",
options: {
target: 'ESNEXT',
declaration: !__DEV__,
useTranspileModule: __DEV__,
},
}, ],
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{
enforce: "pre",
test: /\.js$/,
use: "source-map-loader"
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /test\/fixtures\/.*\.svg$/,
use: [ 'raw-loader' ],
},
{
test: /\.(png|svg|jpg|gif|woff|woff2|eot|ttf|otf)$/,
exclude: /test\/fixtures\//,
use: [
{
loader: 'url-loader',
options: {
limit: 8192
}
}
],
},
]
},
plugins: [
!__DEV__ && new Clean(["static/dist/!(vendor*.js)"]),
__DEV__ && new webpack.NamedModulesPlugin(),
__DEV__ && new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'__DEV__': JSON.stringify(__DEV__ ? true : false),
}),
// new webpack.DllReferencePlugin({
// context: __dirname,
// manifest: require(`${Dist}/vendor-manifest.json`),
// }),
new HtmlWebpackPlugin({
__DEV__: __DEV__,
template: './src/index.ejs',
filename: __DEV__ ? '../../index.html' : '../index.html',
inject: false,
alwaysWriteToDisk: true
}),
new HtmlWebpackHarddiskPlugin(),
new AutoDllPlugin({
inject: true, // will inject the DLL bundle to index.html
debug: true,
filename: '[name]_[hash:5].js',
entry: {
vendor: [
'react', 'emotion', 'hydux', 'hydux-mutator', 'hydux-react',
'lru-cache', 'parse5', 'react-clipboard.js', 'react-contexify',
'react-dropzone', 'tinycolor2', 'tslib', './src/vendor.ts'
]
}
}),
!__DEV__ && new OfflinePlugin({
appShell: `/${Name}/`,
responseStrategy: 'cache-first',
caches: {
main: ['**/*.js', '**/*.{svg,png,jpg}', '*.chunk.js', '*.worker.js', ':externals:'],
additional: [],
optional: [':rest:']
},
externals: [
`/${Name}/`
],
exclude: ['**/.*', '**/*.map', '**/*.gz'],
ServiceWorker: {
events: true,
publicPath: `/${Name}/sw.js`
}
}),
].filter(Boolean),
};