lincd-cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +373 -0
- package/README.md +60 -0
- package/cli.js +1238 -0
- package/config-generator.js +531 -0
- package/defaults/.npmignore +11 -0
- package/defaults/Gruntfile.js +16 -0
- package/defaults/create_migration.js +155 -0
- package/defaults/create_migration.ts +7 -0
- package/defaults/defaultModule/Index.js +30 -0
- package/defaults/defaultModule/Index.scss +19 -0
- package/defaults/defaultModule/Index.tsx +25 -0
- package/defaults/defaultModule/data.json +56 -0
- package/defaults/defaultModule/defaultOntology.json +23 -0
- package/defaults/defaultModule/index.ts +12 -0
- package/defaults/defaultModule/ontology.js +21 -0
- package/defaults/defaultModule/ontology.ts +16 -0
- package/defaults/gitignorefile +4 -0
- package/defaults/index.ts +13 -0
- package/defaults/ontology.ts +16 -0
- package/defaults/package.json +24 -0
- package/defaults/providers.ts +1 -0
- package/defaults/tsconfig-es5.json +19 -0
- package/defaults/tsconfig.json +21 -0
- package/index.js +18 -0
- package/package.json +68 -0
- package/plugins/declaration-plugin.js +248 -0
- package/plugins/externalise-modules.js +159 -0
- package/plugins/watch-run.js +47 -0
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
exports.__esModule = true;
|
|
12
|
+
exports.generateWebpackConfig = exports.setupGrunt = void 0;
|
|
13
|
+
var declaration_plugin_1 = require("./plugins/declaration-plugin");
|
|
14
|
+
var externalise_modules_1 = require("./plugins/externalise-modules");
|
|
15
|
+
var watch_run_1 = require("./plugins/watch-run");
|
|
16
|
+
var colors = require("colors");
|
|
17
|
+
var fs = require('fs');
|
|
18
|
+
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
19
|
+
var chalk = require('chalk');
|
|
20
|
+
var webpack = require('webpack');
|
|
21
|
+
var path = require('path');
|
|
22
|
+
var ExtractTextPlugin = require('extract-text-webpack-plugin');
|
|
23
|
+
var TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
|
|
24
|
+
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
25
|
+
var TerserPlugin = require('terser-webpack-plugin');
|
|
26
|
+
var exec = require('child_process').exec;
|
|
27
|
+
var NODE_ENV = process.env.NODE_ENV;
|
|
28
|
+
var nodeProduction = NODE_ENV == 'production';
|
|
29
|
+
var libraryName = 'lincd';
|
|
30
|
+
function log() {
|
|
31
|
+
var messages = [];
|
|
32
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
33
|
+
messages[_i] = arguments[_i];
|
|
34
|
+
}
|
|
35
|
+
messages.forEach(function (message) {
|
|
36
|
+
console.log(chalk.cyan(message));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function debug(config) {
|
|
40
|
+
var messages = [];
|
|
41
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
42
|
+
messages[_i - 1] = arguments[_i];
|
|
43
|
+
}
|
|
44
|
+
if (config.debug) {
|
|
45
|
+
log.apply(void 0, messages);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function warn() {
|
|
49
|
+
var messages = [];
|
|
50
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
51
|
+
messages[_i] = arguments[_i];
|
|
52
|
+
}
|
|
53
|
+
messages.forEach(function (message) {
|
|
54
|
+
console.log(chalk.red(message));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
var flatten = function (arr) {
|
|
58
|
+
return arr.reduce(function (a, b) {
|
|
59
|
+
return b ? a.concat(b) : a;
|
|
60
|
+
}, []);
|
|
61
|
+
};
|
|
62
|
+
function generateGruntConfig(moduleName, config) {
|
|
63
|
+
if (config === void 0) { config = {}; }
|
|
64
|
+
return function (grunt) {
|
|
65
|
+
setupGrunt(grunt, moduleName, config);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
exports["default"] = generateGruntConfig;
|
|
69
|
+
var generateScopedName = function (name, filename, css) {
|
|
70
|
+
var path = require('path');
|
|
71
|
+
var file = path.basename(filename, '.scss');
|
|
72
|
+
var module = filename.match(/[\\\/]modules[\\\/]([\w\-_]+)/);
|
|
73
|
+
var moduleName;
|
|
74
|
+
if (module) {
|
|
75
|
+
moduleName = module[1];
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
//if we cant find module name from path, we'll use a hash
|
|
79
|
+
//https://stackoverflow.com/questions/6122571/simple-non-secure-hash-function-for-javascript
|
|
80
|
+
var hash = 0;
|
|
81
|
+
if (filename.length == 0) {
|
|
82
|
+
moduleName = '_unknown';
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
for (var i = 0; i < filename.length; i++) {
|
|
86
|
+
var char = filename.charCodeAt(i);
|
|
87
|
+
hash = (hash << 5) - hash + char;
|
|
88
|
+
hash = hash & hash; // Convert to 32bit integer
|
|
89
|
+
}
|
|
90
|
+
moduleName = hash;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// console.log("Module name: "+moduleName);
|
|
94
|
+
// console.log("Returning: " + moduleName + "_" + file + "_" + name);
|
|
95
|
+
return moduleName + '_' + file + '_' + name;
|
|
96
|
+
};
|
|
97
|
+
function setupGrunt(grunt, moduleName, config) {
|
|
98
|
+
var buildServer = !config.environment || config.environment == 'server';
|
|
99
|
+
var buildFrontend = !config.environment || config.environment == 'frontend';
|
|
100
|
+
//when not specified and we ARe building frontend OR we are compiling the server for es5.. or if simply specified, then es5 is targeted
|
|
101
|
+
var targetES5 = (!config.target && (buildFrontend || config.es5Server)) ||
|
|
102
|
+
config.target == 'es5';
|
|
103
|
+
var targetES6 = !config.target || config.target == 'es6';
|
|
104
|
+
var targets = [];
|
|
105
|
+
if (targetES5)
|
|
106
|
+
targets.push('es5');
|
|
107
|
+
if (targetES6)
|
|
108
|
+
targets.push('es6');
|
|
109
|
+
var targetLog = 'building ' + targets.join(', ');
|
|
110
|
+
if (buildServer && !buildFrontend) {
|
|
111
|
+
log(targetLog + ' lib only');
|
|
112
|
+
}
|
|
113
|
+
else if (!buildServer && buildFrontend) {
|
|
114
|
+
log(targetLog + ' dist bundles only');
|
|
115
|
+
}
|
|
116
|
+
else if (buildServer && buildFrontend) {
|
|
117
|
+
if (config.es5Server) {
|
|
118
|
+
log(targetLog + ' lib files & dist bundles');
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
log(targetLog + ' dist bundles and es6 lib files');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
log('invalid configuration combination');
|
|
126
|
+
}
|
|
127
|
+
require('load-grunt-tasks')(grunt);
|
|
128
|
+
//defaults
|
|
129
|
+
grunt.registerTask('default', ['prepare-build', 'concurrent:dev']);
|
|
130
|
+
grunt.registerTask('dev', targetES6 ? ['prepare-build', 'dev-es6'] : ['prepare-build', 'dev-es5']);
|
|
131
|
+
grunt.registerTask('build', targets.map(function (target) { return 'build-' + target; }));
|
|
132
|
+
if (buildFrontend) {
|
|
133
|
+
grunt.registerTask('build-frontend', __spreadArray([
|
|
134
|
+
'prepare-build'
|
|
135
|
+
], targets.map(function (target) { return 'webpack:build-' + target; }), true));
|
|
136
|
+
}
|
|
137
|
+
grunt.registerTask('build-production', flatten([
|
|
138
|
+
'clean:lib',
|
|
139
|
+
'prepare-build',
|
|
140
|
+
buildFrontend ? targets.map(function (target) { return 'webpack:prod-' + target; }) : null,
|
|
141
|
+
buildServer ? ['exec:build-lib'] : null,
|
|
142
|
+
]));
|
|
143
|
+
var prepareBuild = ['postcss:cssjson'];
|
|
144
|
+
if (config.beforeBuildCommand) {
|
|
145
|
+
prepareBuild.push('exec:beforeBuildCommand');
|
|
146
|
+
}
|
|
147
|
+
//specific tasks
|
|
148
|
+
grunt.registerTask('prepare-build', prepareBuild);
|
|
149
|
+
grunt.registerTask('dev-es6-production', [
|
|
150
|
+
'prepare-build',
|
|
151
|
+
'concurrent:dev-prod',
|
|
152
|
+
]);
|
|
153
|
+
grunt.registerTask('dev-es6', ['prepare-build', 'concurrent:dev']);
|
|
154
|
+
grunt.registerTask('dev-es5', ['prepare-build', 'concurrent:dev-es5']);
|
|
155
|
+
//build-es5 is by default just the frontend because the server is es6
|
|
156
|
+
//however some specific modules (like @dacore/module) require the typescript compiler ('build-lib') to run for es5
|
|
157
|
+
//so that core-es5 or browser-core-es5 can internalise its files
|
|
158
|
+
//this can by triggered with es5Server
|
|
159
|
+
grunt.registerTask('build-es5', flatten([
|
|
160
|
+
'postcss',
|
|
161
|
+
buildFrontend ? 'webpack:build-es5' : null,
|
|
162
|
+
config.es5Server ? 'exec:build-lib-es5' : null,
|
|
163
|
+
]));
|
|
164
|
+
grunt.registerTask('build-es6', flatten([
|
|
165
|
+
'prepare-build',
|
|
166
|
+
buildFrontend ? 'webpack:build-es6' : null,
|
|
167
|
+
buildServer ? ['exec:build-lib'] : null,
|
|
168
|
+
'exec:shapes',
|
|
169
|
+
]));
|
|
170
|
+
grunt.registerTask('build-lib', ['prepare-build', 'exec:build-lib']);
|
|
171
|
+
grunt.registerTask('build-production-es5', [
|
|
172
|
+
'prepare-build',
|
|
173
|
+
'webpack:prod-es5',
|
|
174
|
+
'exec:shapes',
|
|
175
|
+
]);
|
|
176
|
+
grunt.registerTask('build-production-es6', [
|
|
177
|
+
'prepare-build',
|
|
178
|
+
'webpack:prod-es6',
|
|
179
|
+
'exec:shapes',
|
|
180
|
+
]);
|
|
181
|
+
// log('setting grunt config');
|
|
182
|
+
grunt.initConfig({
|
|
183
|
+
exec: {
|
|
184
|
+
'build-lib': 'tsc --pretty',
|
|
185
|
+
'build-lib-es5': 'tsc --pretty -p tsconfig-es5.json',
|
|
186
|
+
beforeBuildCommand: config.beforeBuildCommand,
|
|
187
|
+
'server-dev': 'tsc -w',
|
|
188
|
+
test: 'tsc -w',
|
|
189
|
+
shapes: 'lincd shapes',
|
|
190
|
+
'css-declarations': 'tcm -p **/*.scss',
|
|
191
|
+
'postcss-modules': 'yarn postcss --use postcss-import postcss-cssnext postcss-nested postcss-modules -o build/draft.css -i scss/*'
|
|
192
|
+
},
|
|
193
|
+
postcss: {
|
|
194
|
+
options: {
|
|
195
|
+
map: true,
|
|
196
|
+
processors: [require('postcss-modules')({ generateScopedName: generateScopedName })],
|
|
197
|
+
syntax: require('postcss-scss'),
|
|
198
|
+
writeDest: false
|
|
199
|
+
},
|
|
200
|
+
cssjson: {
|
|
201
|
+
src: 'src/**/*.scss'
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
clean: {
|
|
205
|
+
lib: ['lib/']
|
|
206
|
+
},
|
|
207
|
+
concurrent: {
|
|
208
|
+
dev: flatten([
|
|
209
|
+
buildFrontend ? 'webpack:dev' : null,
|
|
210
|
+
buildServer ? 'exec:server-dev' : null,
|
|
211
|
+
// buildServer ? 'watch:css-module-transforms' : null,
|
|
212
|
+
// 'exec:css-declarations-watch'
|
|
213
|
+
]),
|
|
214
|
+
'dev-prod': flatten([
|
|
215
|
+
buildFrontend ? 'webpack:dev-prod' : null,
|
|
216
|
+
buildServer ? 'exec:server-dev' : null,
|
|
217
|
+
// buildServer ? 'watch:css-module-transforms' : null,
|
|
218
|
+
// 'exec:css-declarations-watch'
|
|
219
|
+
]),
|
|
220
|
+
'dev-es5': flatten([
|
|
221
|
+
buildFrontend ? 'webpack:dev-es5' : null,
|
|
222
|
+
buildServer ? 'exec:server-dev' : null,
|
|
223
|
+
// buildServer ? 'watch:css-module-transforms' : null,
|
|
224
|
+
// 'exec:css-declarations-watch'
|
|
225
|
+
]),
|
|
226
|
+
options: {
|
|
227
|
+
logConcurrentOutput: true,
|
|
228
|
+
logTaskName: 3,
|
|
229
|
+
logBlacklist: []
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
webpack: {
|
|
233
|
+
options: {
|
|
234
|
+
stats: {
|
|
235
|
+
chunks: false,
|
|
236
|
+
version: false,
|
|
237
|
+
warningsFilter: function (warning) {
|
|
238
|
+
return warning.indexOf('There are multiple modules') !== -1;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
dev: generateWebpackConfig('dev', moduleName, Object.assign({
|
|
243
|
+
target: 'es6',
|
|
244
|
+
watch: true
|
|
245
|
+
}, config, config.es6, config.dev)),
|
|
246
|
+
'dev-prod': generateWebpackConfig('dev', moduleName, Object.assign({
|
|
247
|
+
target: 'es6',
|
|
248
|
+
watch: true,
|
|
249
|
+
productionMode: true
|
|
250
|
+
}, config, config.es6, config.prod)),
|
|
251
|
+
'dev-es5': generateWebpackConfig('dev-es5', moduleName, Object.assign({
|
|
252
|
+
target: 'es5',
|
|
253
|
+
watch: true
|
|
254
|
+
}, config, config.es5, config.dev)),
|
|
255
|
+
'build-es6': generateWebpackConfig('build-es6', moduleName, Object.assign({
|
|
256
|
+
target: 'es6',
|
|
257
|
+
watch: false
|
|
258
|
+
}, config, config.es6, config.dev)),
|
|
259
|
+
'build-es5': generateWebpackConfig('build-es5', moduleName, Object.assign({
|
|
260
|
+
target: 'es5',
|
|
261
|
+
watch: false
|
|
262
|
+
}, config, config.es5, config.dev)),
|
|
263
|
+
'prod-es5': generateWebpackConfig('prod-es5', moduleName, Object.assign({
|
|
264
|
+
target: 'es5',
|
|
265
|
+
watch: false,
|
|
266
|
+
productionMode: true
|
|
267
|
+
}, config, config.es5, config.prod)),
|
|
268
|
+
'prod-es6': generateWebpackConfig('prod-es6', moduleName, Object.assign({
|
|
269
|
+
target: 'es6',
|
|
270
|
+
watch: false,
|
|
271
|
+
productionMode: true
|
|
272
|
+
}, config, config.es6, config.prod))
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
grunt.config.init.exec = {
|
|
276
|
+
test: 'echo "yey"'
|
|
277
|
+
};
|
|
278
|
+
//load the npm grunt task modules
|
|
279
|
+
[
|
|
280
|
+
'grunt-webpack',
|
|
281
|
+
'grunt-exec',
|
|
282
|
+
'grunt-concurrent',
|
|
283
|
+
'grunt-contrib-clean',
|
|
284
|
+
'@lodder/grunt-postcss',
|
|
285
|
+
].forEach(function (taskName) {
|
|
286
|
+
debug(config, 'loading grunt task ' + taskName);
|
|
287
|
+
var localPath = path.resolve(__dirname, 'node_modules', taskName, 'tasks');
|
|
288
|
+
var localPath2 = path.resolve(__dirname, '..', 'node_modules', taskName, 'tasks');
|
|
289
|
+
var workspacePath = path.resolve(__dirname, '..', '..', 'node_modules', taskName, 'tasks');
|
|
290
|
+
var nestedWorkspacePath = path.resolve(__dirname, '..', '..', '..', 'node_modules', taskName, 'tasks');
|
|
291
|
+
if (fs.existsSync(localPath)) {
|
|
292
|
+
// grunt.loadNpmTasks(taskName);
|
|
293
|
+
debug('Loading from ' + localPath);
|
|
294
|
+
grunt.task.loadTasks(localPath);
|
|
295
|
+
}
|
|
296
|
+
else if (fs.existsSync(localPath2)) {
|
|
297
|
+
// grunt.loadNpmTasks(taskName);
|
|
298
|
+
debug('Loading from ' + localPath2);
|
|
299
|
+
grunt.task.loadTasks(localPath2);
|
|
300
|
+
}
|
|
301
|
+
else if (fs.existsSync(workspacePath)) {
|
|
302
|
+
//windows, so it seems
|
|
303
|
+
debug('Loading from ' + workspacePath);
|
|
304
|
+
grunt.task.loadTasks(workspacePath);
|
|
305
|
+
}
|
|
306
|
+
else if (fs.existsSync(nestedWorkspacePath)) {
|
|
307
|
+
//mac / linux
|
|
308
|
+
debug('Loading from ' + nestedWorkspacePath);
|
|
309
|
+
grunt.task.loadTasks(nestedWorkspacePath);
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
warn("Could not load grunt task module ".concat(taskName, "\nCould not find task at any of these paths:\n").concat(localPath, "\n").concat(localPath2, "\n").concat(workspacePath, "\n").concat(nestedWorkspacePath));
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
exports.setupGrunt = setupGrunt;
|
|
317
|
+
function generateWebpackConfig(buildName, moduleName, config) {
|
|
318
|
+
if (config === void 0) { config = {}; }
|
|
319
|
+
if (!config.externals)
|
|
320
|
+
config.externals = {};
|
|
321
|
+
if (!config.internals)
|
|
322
|
+
config.internals = [];
|
|
323
|
+
var watch = config.watch;
|
|
324
|
+
var productionMode = nodeProduction || config.productionMode;
|
|
325
|
+
var es5 = config.target == 'es5';
|
|
326
|
+
var es6 = config.target == 'es6';
|
|
327
|
+
var configFile;
|
|
328
|
+
if (es5 && fs.existsSync('tsconfig-es5.json')) {
|
|
329
|
+
configFile = 'tsconfig-es5.json';
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
configFile = 'tsconfig.json';
|
|
333
|
+
}
|
|
334
|
+
if (!fs.existsSync(configFile)) {
|
|
335
|
+
warn('Cannot find ' + configFile);
|
|
336
|
+
process.exit();
|
|
337
|
+
}
|
|
338
|
+
var plugins = [
|
|
339
|
+
new webpack.DefinePlugin({
|
|
340
|
+
'process.env.BROWSER': JSON.stringify(true),
|
|
341
|
+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
|
|
342
|
+
}),
|
|
343
|
+
new webpack.NoEmitOnErrorsPlugin(),
|
|
344
|
+
new ExtractTextPlugin(config.cssFileName
|
|
345
|
+
? config.cssFileName
|
|
346
|
+
: libraryName + '.' + moduleName + '.css'),
|
|
347
|
+
new MiniCssExtractPlugin({
|
|
348
|
+
// linkType: false,
|
|
349
|
+
filename: config.cssFileName
|
|
350
|
+
? config.cssFileName
|
|
351
|
+
: libraryName + '.' + moduleName + '.css'
|
|
352
|
+
}),
|
|
353
|
+
];
|
|
354
|
+
if (config.debug) {
|
|
355
|
+
plugins.push(new watch_run_1["default"]());
|
|
356
|
+
}
|
|
357
|
+
if (config.afterBuildCommand) {
|
|
358
|
+
plugins.push({
|
|
359
|
+
apply: function (compiler) {
|
|
360
|
+
compiler.hooks.afterEmit.tap('AfterEmitPlugin', function (compilation) {
|
|
361
|
+
exec(config.afterBuildCommand, function (err, stdout, stderr) {
|
|
362
|
+
if (stdout)
|
|
363
|
+
process.stdout.write(stdout);
|
|
364
|
+
if (stderr)
|
|
365
|
+
process.stderr.write(stderr);
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
if (config.analyse) {
|
|
372
|
+
plugins.push(new BundleAnalyzerPlugin());
|
|
373
|
+
}
|
|
374
|
+
if (es6 || config.declarations === true) {
|
|
375
|
+
plugins.push(new declaration_plugin_1["default"]({
|
|
376
|
+
out: (config.filename ? config.filename : libraryName + '.' + moduleName) +
|
|
377
|
+
'.d.ts',
|
|
378
|
+
root: config.outputPath ? config.outputPath : './lib/',
|
|
379
|
+
debug: 'debug' in config ? config.debug : false
|
|
380
|
+
}));
|
|
381
|
+
}
|
|
382
|
+
var resolvePlugins = [
|
|
383
|
+
new TsconfigPathsPlugin({
|
|
384
|
+
configFile: configFile,
|
|
385
|
+
silent: true
|
|
386
|
+
}),
|
|
387
|
+
];
|
|
388
|
+
var aliases = config.alias || {};
|
|
389
|
+
var rules = [
|
|
390
|
+
{
|
|
391
|
+
test: /\.(scss|css)$/,
|
|
392
|
+
use: [
|
|
393
|
+
MiniCssExtractPlugin.loader,
|
|
394
|
+
{
|
|
395
|
+
loader: 'css-loader',
|
|
396
|
+
options: {
|
|
397
|
+
url: false
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
loader: 'postcss-loader',
|
|
402
|
+
options: {
|
|
403
|
+
postcssOptions: {
|
|
404
|
+
plugins: {
|
|
405
|
+
'postcss-import': {},
|
|
406
|
+
'postcss-cssnext': {},
|
|
407
|
+
'postcss-nested': {},
|
|
408
|
+
// "postcss-scss": {}, //<-- only add this back if the build gets stuck on //comments in scss files, but I dont think that will be the case anymore
|
|
409
|
+
'postcss-modules': {
|
|
410
|
+
//by default postcss-modules will put out a json file right next to the original css / scss file, this method defines what classnames to use
|
|
411
|
+
generateScopedName: generateScopedName,
|
|
412
|
+
globalModulePaths: [/tailwind/]
|
|
413
|
+
},
|
|
414
|
+
tailwindcss: {
|
|
415
|
+
purge: {
|
|
416
|
+
enabled: productionMode,
|
|
417
|
+
content: [
|
|
418
|
+
'./src/**/*.tsx',
|
|
419
|
+
'./src/**/*.ts',
|
|
420
|
+
//also include @dacore modules which are internalized with the "internal" config option
|
|
421
|
+
//imports like ... from '@dacore/module/lib/views/SomeView' will
|
|
422
|
+
//these modules should live in the node_modules folder of the root of the site
|
|
423
|
+
//TODO: remake this with multiple lincd modules
|
|
424
|
+
// '../../node_modules/@dacore/*/lib/**/*.js',
|
|
425
|
+
// './node_modules/@dacore/*/lib/**/*.js',
|
|
426
|
+
]
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
loader: 'sass-loader',
|
|
435
|
+
options: { sourceMap: true }
|
|
436
|
+
},
|
|
437
|
+
]
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
test: /\.tsx?$/,
|
|
441
|
+
use: [
|
|
442
|
+
{
|
|
443
|
+
loader: 'ts-loader?' +
|
|
444
|
+
JSON.stringify({
|
|
445
|
+
configFile: configFile,
|
|
446
|
+
compilerOptions: {
|
|
447
|
+
declaration: !es5
|
|
448
|
+
}
|
|
449
|
+
})
|
|
450
|
+
},
|
|
451
|
+
]
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
enforce: 'pre',
|
|
455
|
+
test: /\.js$/,
|
|
456
|
+
use: [
|
|
457
|
+
{
|
|
458
|
+
loader: 'source-map-loader'
|
|
459
|
+
},
|
|
460
|
+
]
|
|
461
|
+
},
|
|
462
|
+
];
|
|
463
|
+
if (es5 && config.internalsources && config.internalsources.length > 0) {
|
|
464
|
+
//usually a module that transpiles to es5 will only have es5 code in the bundle.
|
|
465
|
+
//however a module that INTERNALISES other dacore modules will directly include es6 code from @dacore/other_modules/lib
|
|
466
|
+
//which eventually results in an import of @dacore/core being bundled as 'const =', which trips up old browsers
|
|
467
|
+
//so we fix that here by just referring directly to the typescript source instead of the transpiled js for internalised modules
|
|
468
|
+
//however this means that for internalised modules THE SOURCE CODE NEEDS TO BE AVAILABLE. This is currently NOT the case with how we publish modules to yarn
|
|
469
|
+
//so that means internalised modules need to be LOCALLY AVAILABLE with yarn workspaces
|
|
470
|
+
plugins.push(new webpack.NormalModuleReplacementPlugin(/\lincd\/lib\//, function (resource, match) {
|
|
471
|
+
var moduleName = resource.request.match(/lincd\/lib\//)[1];
|
|
472
|
+
if (config.internalsources.indexOf(moduleName) !== -1) {
|
|
473
|
+
console.log(colors.magenta('internal sources + ES5: Replacing /lib/ with /src/ for source-internalised module ' +
|
|
474
|
+
moduleName));
|
|
475
|
+
resource.request = resource.request.replace('/lib/', '/src/');
|
|
476
|
+
console.log(colors.magenta('internal sources + ES5: ' + resource.request));
|
|
477
|
+
console.log(colors.red("WARNING: Make sure you have the TYPESCRIPT SOURCE FILES of the modules listed as 'internal' AVAILABLE ON YOUR LOCAL MACHINE. So if you check in node_modules/your-internalised-module - that should be a symbolic link and you will find a 'src' folder with typescript files there."));
|
|
478
|
+
}
|
|
479
|
+
}));
|
|
480
|
+
}
|
|
481
|
+
return {
|
|
482
|
+
entry: config.entry ? config.entry : './src/index.ts',
|
|
483
|
+
output: {
|
|
484
|
+
filename: (config.filename ? config.filename : libraryName + '.' + moduleName) +
|
|
485
|
+
(es5 ? '.es5' : '') +
|
|
486
|
+
'.js',
|
|
487
|
+
path: path.resolve(process.cwd(), config.bundlePath || 'dist'),
|
|
488
|
+
devtoolModuleFilenameTemplate: moduleName + '/[resource-path]'
|
|
489
|
+
},
|
|
490
|
+
devtool: productionMode ? 'cheap-source-map' : 'cheap-source-map',
|
|
491
|
+
mode: productionMode ? 'production' : 'development',
|
|
492
|
+
//fixing a persistent but strange build error here that showed up once, this is a workaround. See: https://github.com/webpack-contrib/css-loader/issues/447
|
|
493
|
+
node: {
|
|
494
|
+
fs: 'empty',
|
|
495
|
+
child_process: 'empty'
|
|
496
|
+
},
|
|
497
|
+
resolve: {
|
|
498
|
+
extensions: ['.webpack.js', '.js', '.ts', '.tsx', '.json'],
|
|
499
|
+
alias: aliases,
|
|
500
|
+
plugins: resolvePlugins
|
|
501
|
+
},
|
|
502
|
+
resolveLoader: {
|
|
503
|
+
modules: [
|
|
504
|
+
path.join(__dirname, 'plugins'),
|
|
505
|
+
path.join(__dirname, 'node_modules'),
|
|
506
|
+
'node_modules',
|
|
507
|
+
]
|
|
508
|
+
},
|
|
509
|
+
optimization: {
|
|
510
|
+
minimize: productionMode,
|
|
511
|
+
minimizer: [new TerserPlugin()]
|
|
512
|
+
},
|
|
513
|
+
watch: watch,
|
|
514
|
+
module: {
|
|
515
|
+
rules: rules
|
|
516
|
+
},
|
|
517
|
+
//See plugins/externalise-modules.ts We're passing in a function here that determines what to exclude from the bundle and what not
|
|
518
|
+
//See also https://webpack.js.org/configuration/externals/
|
|
519
|
+
externals: (0, externalise_modules_1["default"])(config, es5),
|
|
520
|
+
plugins: plugins,
|
|
521
|
+
stats: {
|
|
522
|
+
errorDetails: config.debug,
|
|
523
|
+
chunks: false,
|
|
524
|
+
children: false,
|
|
525
|
+
version: true,
|
|
526
|
+
hash: false,
|
|
527
|
+
modules: false
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
exports.generateWebpackConfig = generateWebpackConfig;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var buildTools = require('@dacore/build-tools');
|
|
2
|
+
module.exports = buildTools.generateGruntConfig('${module_name}', {
|
|
3
|
+
externals: {
|
|
4
|
+
react: 'React',
|
|
5
|
+
'react-dom': 'ReactDOM',
|
|
6
|
+
}, //externals: list of non-dacore modules that are already loaded and made globally available by one of the dependencies of this module
|
|
7
|
+
//internals: [],//list of dacore modules (their package name, can be with or without '@dacore/') that you want to INCLUDE in the bundle (as opposed to the module its own bundle being a dependency)
|
|
8
|
+
//alias:{},//webpack alias -> maps on type of npm path to another
|
|
9
|
+
//target:"es5"|"es6",
|
|
10
|
+
//environment:"server"|"frontend",
|
|
11
|
+
//outputPath:string,
|
|
12
|
+
//es5Server:boolean
|
|
13
|
+
//es5:{},//es5 specific config, use same properties as above
|
|
14
|
+
//es6:{},//es6 specific config, use same properties as above
|
|
15
|
+
//debug:false,//debug the build process
|
|
16
|
+
});
|