-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
124 lines (119 loc) · 3.55 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
const webpack = require('webpack');
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const parsedArgs = require('yargs').argv;
const packageJson = require('./package.json');
// input dir
const SRC_DIR = path.resolve(__dirname, './src');
// output dir
const BUILD_DIR = path.resolve(__dirname, './dist');
const { mode = 'development', devserverPort = 9000 } = parsedArgs;
const isDevMode = mode !== 'production';
const peerDependencies = new Set(Object.keys(packageJson.peerDependencies));
const output = {
path: BUILD_DIR,
publicPath: '/static/assets/', // necessary for lazy-loaded chunks
};
if (isDevMode) {
output.filename = '[name].entry.js';
output.chunkFilename = '[name].chunk.js';
} else {
output.filename = '[name].[chunkhash].entry.js';
output.chunkFilename = '[name].[chunkhash].chunk.js';
}
const config = {
node: {
fs: 'empty',
},
entry: {
main: 'src/entry.ts',
},
output: {
path: BUILD_DIR,
publicPath: '/dist/',
libraryTarget: 'umd',
},
resolve: {
alias: {
src: SRC_DIR,
},
extensions: ['.ts', '.tsx', '.js', '.jsx'],
symlinks: false,
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
'thread-loader',
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
// disable gzip compression for cache files
// faster when there are millions of small files
cacheCompression: false,
plugins: ['emotion'],
},
},
{
loader: 'ts-loader',
options: {
// transpile only in happyPack mode
// type checking is done via fork-ts-checker-webpack-plugin
happyPackMode: true,
transpileOnly: true,
// must override compiler options here, even though we have set
// the same options in `tsconfig.json`, because they may still
// be overriden by `tsconfig.json` in node_modules subdirectories.
compilerOptions: {
esModuleInterop: false,
importHelpers: false,
module: 'esnext',
target: 'esnext',
},
},
},
],
},
{
test: /\.(jpg|gif|png)$/,
use: [
{
loader: 'url-loader',
options: {
// using file-loader would be nice, but there's no good plan
// to get superset to load files from the correct domain.
// Once we figure that out, this could be set to a reasonable limit.
limit: Infinity,
},
},
],
},
],
},
plugins: [
new CleanWebpackPlugin({
dry: false,
}),
new webpack.DefinePlugin({
'process.env.PACKAGE_NAME': JSON.stringify(packageJson.name),
}),
],
externals: [
// define externals based on the peerDependencies in package.json
// if we can figure out how to get a plugin to access externals via a means
// other than global variables, let's do that.
function externalizePeerDependencies(context, request, callback) {
if (peerDependencies.has(request)) {
// superset attaches shared modules to the window, prepended with "__superset__/"
return callback(null, `__superset__/${request}`);
}
return callback();
},
],
// TODO make source maps work
devtool: isDevMode ? 'eval-source-map' : false,
};
module.exports = config;