-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathwebpack.config.js
More file actions
executable file
·148 lines (143 loc) · 3.89 KB
/
webpack.config.js
File metadata and controls
executable file
·148 lines (143 loc) · 3.89 KB
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
const path = require('path')
const webpack = require('webpack')
const FileManagerPlugin = require('filemanager-webpack-plugin');
const StyleLintPlugin = require('stylelint-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
var baseConfig = {
mode: 'development',
module: {
rules: [
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/env',
{
'targets': {
'ie': '11',
'chrome': '52', // Chromium in Sketchup 2017
},
//'useBuiltIns': 'usage', // automatically include polyfills for used JavaScript features (e.g. Promise)
'useBuiltIns': 'entry', // Not 'usage' because it significantly increases size.
'corejs': 'core-js@3',
'exclude': [
'@babel/plugin-transform-regenerator', // This comes with Promise polyfill, but increases size. We don't need support for async/await.
],
},
],
],
plugins: [
'@babel/plugin-transform-runtime',
],
},
},
exclude: /node_modules/
}
]
},
devServer: {
historyApiFallback: {
index: 'tutorial/ae_bridgelibrary/tutorial.html'
},
noInfo: true
},
performance: {
hints: false
},
devtool: 'source-map',
plugins: []
}
var testConfig = Object.assign({}, baseConfig, {
entry: [
'./src/spec/bridge-htmldialog.spec.js',
'./src/spec/bridge.spec.js',
'./src/spec/requesthandler-htmldialog.spec.js',
'./src/spec/requesthandler-webdialog.spec.js'
],
output: {
filename: 'spec.bundle.js',
path: path.resolve(__dirname, 'build'),
}
});
var compiledIntoAppConfig = Object.assign({}, baseConfig, {
entry: [
'core-js/stable/promise', // Include Promise polyfill
'./src/interactive-test/main.js'
],
output: {
filename: 'main.bundle.js',
path: path.resolve(__dirname, 'build'),
}
});
var standaloneLibraryConfig = Object.assign({}, baseConfig, {
entry: [
'core-js/stable/promise', // Include Promise polyfill
'./src/js/bridge.js'
],
output: {
filename: 'bridge.js',
path: path.resolve(__dirname, 'dist'),
library: 'Bridge',
libraryExport: 'default',
libraryTarget: 'umd',
},
plugins: [
new FileManagerPlugin({
events: {
onEnd: {
copy: [
{source: './dist/bridge.js', destination: './tutorial/ae_bridgelibrary/bridge.js'},
{source: './dist/bridge.js', destination: './sample/sample_extension/js/bridge.js'},
]
}
}
})
]
});
if (process.env.NODE_ENV === 'production') {
module.exports = [
compiledIntoAppConfig,
standaloneLibraryConfig
].map((config) => {
config.mode = 'production'
config.optimization = Object.assign({}, config.optimization, {
minimize: true,
moduleIds: 'named',
chunkIds: 'named'
});
config.plugins = config.plugins.concat([
new TerserPlugin({
terserOptions: {
ecma: 5,
mangle: {
reserved: ['Sketchup']
},
ie8: true,
//keep_classnames: true, // Not needed, it preserves names of public exports, e.g. Bridge.
//keep_fnames: true, // Not needed, it preserves names of public exports, functions of Bridge.
},
}, {}),
]);
return config;
});
} else {
standaloneLibraryConfig.optimization = {
minimize: false,
moduleIds: 'named',
chunkIds: 'named'
}
testConfig.optimization = {
minimize: false,
moduleIds: 'named',
chunkIds: 'named'
}
standaloneLibraryConfig.devtool = 'source-map' // For debugging
module.exports = [
compiledIntoAppConfig,
standaloneLibraryConfig,
testConfig
];
}