-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.js
163 lines (138 loc) · 4.54 KB
/
webpack.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
var webpack = require('webpack');
var fs = require('fs');
var path = require('path');
function NullPlugin() {
this.apply = function(){};
}
// Give process a more descriptive name than just "npm"
process.title = 'lmv-webpack';
/**
* Exports a function that returns an array of webpack configurations to run in parallel.
*
* @param {object} env - Object containing command-line supplied variables
*/
module.exports = function(env) {
const PROD_BUILD = env.BUILD_PROD;
// Defaults for local developer builds
var build_version = env.BUILD_VERSION;
var build_type = env.BUILD_TYPE || 'local';
/**
*
* @param {boolean} [extractCss=false] - Whether a CSS file will get generated (true) or not (false)
*/
function getModuleConfig(extractCss) {
var moduleConfig = {
rules: [
{
test: /\.js$/,
include: [
path.resolve(__dirname, "../extensions"),
],
exclude: [/\.min.js$/], //the min.js is for zlib pre-built modules
use: {
loader: 'babel-loader',
options: {
cacheDirectory: '.babel',
presets: ['@babel/preset-env'],
compact: false,
retainLines: true
}
}
},
{
test: /\.svg$/,
loader: 'svg-url-loader'
}
],
noParse: [
/\.min.js$/
]
};
if (extractCss) {
} else {
// CSS styles will be included into the HTML by inserting <style> tags
moduleConfig.rules.push({
test: /\.css$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" },
]
});
}
return moduleConfig;
}
var outputPath = path.resolve(__dirname, "./build");
function getExternalExtensions() {
return [
// First is the path to extension's entry point,
// Second (and all others) are the extension IDs.
{
src: './Measure/Measure',
ids: ['Autodesk.Measure'],
},
{
src: './Markup/Markup',
ids: [
'Autodesk.Viewing.MarkupsCore',
'Autodesk.Viewing.MarkupsGui'
],
},
];
}
function getExtensionEntryKey(ee) {
// Given ee.src == './extensions/Something/file.js'
// then key == 'Something'
let key = ee.src.split('/')[2];
return key;
}
function getExtensionEntries() {
var entries = {};
var extensions = getExternalExtensions();
extensions.forEach((ee)=>{
let key = getExtensionEntryKey(ee);
entries[key] = ee.src;
});
return entries;
}
//Can be run to produces minified or non-minified assets
var extensionsWebConfig = {
entry: getExtensionEntries(),
output: {
path: outputPath + '/extensions/',
filename: PROD_BUILD ? '[name]/[name].min.js' : '[name]/[name].js',
library: 'Autodesk.Extensions.[name]',
libraryTarget: 'assign'
},
module: getModuleConfig(false),
resolveLoader: { modules: [ 'node_modules', 'deployment/node_modules', 'deployment/webpack' ] },
resolve: {
alias: {
'opentype.js$': path.resolve(__dirname, '../node_modules/opentype.js/dist/opentype.js'),
}
},
plugins: [
],
};
// tasks
var nameToTask = {
"lmv-extensions": extensionsWebConfig,
};
var exportTasks = [];
if (env.BUILD_TASK === 'lmv-all') {
for (var taskId in nameToTask) {
if (nameToTask.hasOwnProperty(taskId))
exportTasks.push(nameToTask[taskId]);
}
} else {
var task = nameToTask[env.BUILD_TASK];
if (!task)
throw new Error(`Invalid env.BUILD_TASK value: (${env.BUILD_TASK})`);
exportTasks = [task];
}
exportTasks.forEach((task)=>{
let isProd = PROD_BUILD && (task.target !== 'node');
task.mode = isProd ? 'production' : 'development';
task.devtool = isProd ? 'source-map' : false;
})
return exportTasks;
} // module.exports