-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
135 lines (124 loc) · 3.82 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
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
module.exports = (_, argv) => {
let type = 'development';
if (argv.production) {
type = 'production';
} else if (argv.demo) {
type = 'demo';
} else if (argv.test) {
type = 'test';
}
const base = {
mode: 'production',
module: {
rules: [
{
test: /\.(ts|js)$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: type === 'development',
},
},
],
},
{
test: /\.[vf]f?sh$/,
use: [
{
loader: path.resolve('./tools/shadersLoader.js'),
},
],
},
],
},
resolve: {
extensions: ['.ts', '.js'],
},
};
const library = {
...base,
entry: './src/index.ts',
output: {
filename: 'deck2gislayer.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
libraryTarget: 'umd',
// webpack для umd использует window, которого может не быть в nodejs окружении.
// вероятно поправили в 5 webpack, тогда можно будет удалить globalObject
// https://github.com/webpack/webpack/pull/8625
globalObject: "typeof self !== 'undefined' ? self : this",
},
};
const demo = {
...base,
entry: './demo/index.ts',
output: {
filename: 'demo.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
},
};
const test = {
...base,
entry: './test/index.ts',
output: {
filename: 'test.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
},
plugins: [
new CleanWebpackPlugin(),
new CopyPlugin([
{
from: 'test/index.html',
to: 'test.html',
},
]),
],
};
if (type === 'production') {
return [library];
}
if (type === 'demo') {
return [library, demo];
}
if (type === 'test') {
return [test];
}
const devConfig = {
mode: 'development',
devtool: 'eval-source-map',
plugins: [new ForkTsCheckerWebpackPlugin()],
devServer: {
contentBase: path.resolve(__dirname, 'dist'),
host: 'localhost',
port: 3030,
stats: {
modules: false,
hash: false,
version: false,
assets: false,
entrypoints: false,
builtAt: false,
// https://github.com/TypeStrong/ts-loader#transpileonly-boolean-defaultfalse
warningsFilter: /export .* was not found in /,
},
disableHostCheck: true,
clientLogLevel: 'error',
// Чтобы скрипт можно было тянуть с другого домена, например, в visual-comparator
headers: {
'Access-Control-Allow-Origin': '*',
},
},
};
return [
{ ...library, ...devConfig },
{ ...demo, ...devConfig },
];
};