-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base-webpack.config.js
206 lines (195 loc) · 5.42 KB
/
base-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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
const path = require('path');
// werbpack plugin
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
// visual configuration json path
const pbivizPath = "./pbiviz.json";
const pbivizFile = require(path.join(__dirname, pbivizPath));
const { version } = require("./charticulator/package.json");
// babel options to support IE11
let babelOptions = {
"presets": [
[
require.resolve('@babel/preset-env'),
{
useBuiltIns: "entry",
corejs: 3,
modules: false
}
],
[
require.resolve('@babel/preset-react')
],
],
plugins: [
[
require.resolve('babel-plugin-module-resolver'),
{
root: ['./'],
},
],
],
sourceType: "unambiguous", // tell to babel that the project can contains different module types, not only es2015 modules
cacheDirectory: path.join(".tmp", "babelCache") // path for chace files
};
const resolve = {
extensions: ['.tsx', '.ts', '.jsx', '.js', '.css','.json'],
alias: {
charticulator: path.resolve(__dirname, "./charticulator/"),
visual: path.resolve(__dirname, './src'),
src: path.resolve(__dirname, "./charticulator/src"),
assets: path.resolve(__dirname, './assets'),
resources: path.resolve(__dirname, "./charticulator/resources"),
},
};
const moduleRules = {
rules: [
{
parser: {
amd: false
}
},
{
test: /\.pegjs$/,
loader: require.resolve('pegjs-loader'),
options: {
allowedStartRules: ["start", "start_text"],
cache: true,
optimize: "size"
}
},
{
test: /\.tmplt$/,
loader: require.resolve('raw-loader'),
},
{
test: /(\.ts)x|\.ts$/,
use: [
{
loader: require.resolve('babel-loader'),
options: {
// presets: ['@babel/react', '@babel/env'],
plugins: [
[
require.resolve('babel-plugin-module-resolver'),
{
root: ['./'],
alias: {
},
},
],
],
},
},
{
loader: require.resolve('ts-loader'),
options: {
transpileOnly: false,
experimentalWatchApi: false,
}
}
],
exclude: [/node_modules/],
include: /powerbi-visuals-|src|precompile\\visualPlugin.ts/,
},
{
test: /(\.js)x|\.js$/,
use: [
{
loader: require.resolve('babel-loader'),
options: babelOptions
}
],
exclude: [/node_modules/]
},
{
test: /\.json$/,
loader: require.resolve('json-loader'),
type: "javascript/auto"
},
{
test: /\.(css|scss|less)?$/,
use: [
require.resolve('style-loader'),
require.resolve('css-loader'),
require.resolve('sass-loader')
],
},
{
test: /\.(woff|ttf|ico|woff2|jpg|jpeg|png|webp|svg)$/i,
use: [
{
loader: 'base64-inline-loader'
}
]
}
]
};
const externals = {
"powerbi-visuals-api": 'null',
"fakeDefine": 'false',
"corePowerbiObject": "Function('return this.powerbi')()",
"realWindow": "Function('return this')()",
"CHARTICULATOR_PACKAGE": `{version:${version}}`
};
const performance = {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000
};
const plugins = [
new webpack.SourceMapDevToolPlugin({
filename: '[name].js.map',
}),
new webpack.DefinePlugin({
CHARTICULATOR_PACKAGE: JSON.stringify({
version,
buildTimestamp: new Date().getTime()
})
}),
new webpack.ProvidePlugin({
window: 'realWindow',
define: 'fakeDefine',
powerbi: 'corePowerbiObject'
})
];
const devServer = {
static: false,
compress: true,
port: 8080, // dev server port
hot: false,
liveReload: false,
webSocketServer: false,
https: {
},
headers: {
"access-control-allow-origin": "*",
"cache-control": "public, max-age=0"
},
devMiddleware: {
writeToDisk: true
},
};
const optimization = {
concatenateModules: true,
minimize: true // enable minimization for create *.pbiviz file less than 2 Mb, can be disabled for dev mode
};
module.exports = {
optimization,
devtool: 'source-map',
mode: "development",
module: moduleRules,
resolve,
externals,
performance,
devServer,
output: {
publicPath: '/assets',
path: path.join(__dirname, "/.tmp", "drop"),
library: pbivizFile.visual.guid,
libraryTarget: 'var',
},
plugins: [
...plugins,
]
};