lincd-cli 0.2.42 → 0.2.44

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.
@@ -1,14 +1,16 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ 'use strict';
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : {default: mod};
6
+ };
7
+ Object.defineProperty(exports, '__esModule', {value: true});
6
8
  exports.generateWebpackConfig = void 0;
7
- const declaration_plugin_1 = __importDefault(require("./plugins/declaration-plugin"));
8
- const externalise_modules_1 = __importDefault(require("./plugins/externalise-modules"));
9
- const watch_run_1 = __importDefault(require("./plugins/watch-run"));
10
- const utils_1 = require("./utils");
11
- const colors = require("colors");
9
+ const declaration_plugin_1 = __importDefault(require('./plugins/declaration-plugin'));
10
+ const externalise_modules_1 = __importDefault(require('./plugins/externalise-modules'));
11
+ const watch_run_1 = __importDefault(require('./plugins/watch-run'));
12
+ const utils_1 = require('./utils');
13
+ const colors = require('colors');
12
14
  // console.log('Webpack '+require('webpack/package.json').version);
13
15
  // console.log('ts-loader '+require('ts-loader/package.json').version);
14
16
  const fs = require('fs');
@@ -27,354 +29,366 @@ const NODE_ENV = process.env.NODE_ENV;
27
29
  const nodeProduction = NODE_ENV == 'production';
28
30
  // const libraryName = 'lincd';
29
31
  process.traceDeprecation = true;
32
+
30
33
  function getLincdPackagePaths(packages) {
31
- if (!packages) {
32
- let pkgJson = (0, utils_1.getPackageJSON)();
33
- packages = Object.assign(Object.assign({}, pkgJson.dependencies), pkgJson.devDependencies);
34
+ if (!packages) {
35
+ let pkgJson = (0, utils_1.getPackageJSON)();
36
+ packages = Object.assign(Object.assign({}, pkgJson.dependencies), pkgJson.devDependencies);
37
+ }
38
+ let lincdPackagePaths = [];
39
+ for (var dependency of Object.keys(packages)) {
40
+ try {
41
+ let pkgJson = require(dependency + '/package.json');
42
+ if (pkgJson.lincd) {
43
+ let pkgPath = require.resolve(dependency + '/package.json');
44
+ lincdPackagePaths.push(pkgPath.substring(0, pkgPath.length - 13));
45
+ }
46
+ } catch (err) {
47
+ // console.log("could not find "+dependency);
34
48
  }
35
- let lincdPackagePaths = [];
36
- for (var dependency of Object.keys(packages)) {
37
- try {
38
- let pkgJson = require(dependency + '/package.json');
39
- if (pkgJson.lincd) {
40
- let pkgPath = require.resolve(dependency + '/package.json');
41
- lincdPackagePaths.push(pkgPath.substring(0, pkgPath.length - 13));
42
- }
43
- }
44
- catch (err) {
45
- // console.log("could not find "+dependency);
46
- }
47
- }
48
- return lincdPackagePaths;
49
+ }
50
+ return lincdPackagePaths;
49
51
  }
52
+
50
53
  function generateWebpackConfig(buildName, moduleName, config = {}) {
51
- if (!config.externals)
52
- config.externals = {};
53
- if (!config.internals)
54
- config.internals = [];
55
- var watch = config.watch;
56
- var productionMode = nodeProduction || config.productionMode;
57
- var es5 = config.target == 'es5';
58
- var es6 = config.target == 'es6';
59
- //remove the scope (used for filenames for example)
60
- var cleanModuleName = moduleName.replace(/@[\w\-]+\//, '');
61
- var configFile;
62
- if (es5 && fs.existsSync('tsconfig-es5.json')) {
63
- configFile = 'tsconfig-es5.json';
64
- }
65
- else {
66
- configFile = 'tsconfig.json';
67
- }
68
- if (!fs.existsSync(configFile)) {
69
- (0, utils_1.warn)('Cannot find ' + configFile);
70
- process.exit();
71
- }
72
- let tsConfig = JSON.parse(fs.readFileSync(configFile));
73
- var plugins = [
74
- // new webpack.DefinePlugin({
75
- // 'process.env.BROWSER': JSON.stringify(true),
76
- // 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
77
- // }),
78
- // new webpack.NoEmitOnErrorsPlugin(),
79
- // new ExtractTextPlugin(config.cssFileName ? config.cssFileName : cleanModuleName + '.css'),
80
- new MiniCssExtractPlugin({
81
- // linkType: false,
82
- filename: config.cssFileName ? config.cssFileName : cleanModuleName + '.css',
83
- }),
84
- //currently not compatible with webpack 5
85
- // new WebpackLicencePlugin({
86
- // excludedPackageTest: (packageName, version) => {
87
- // return packageName.indexOf('lincd') !== -1;
88
- // },
89
- // }),
90
- //NOTE: grunt comes with a copy task, which is ran during `yarn lincd build` but cannot run during `yarn lincd dev`
91
- //so here we ALSO copy the same files to cover dev flow
92
- new CopyPlugin({
93
- patterns: [
94
- {
95
- from: 'src/**/*.scss',
96
- to({ context, absoluteFilename }) {
97
- // console.log(chalk.magenta(context),chalk.magenta(absoluteFilename),process.cwd());
98
- //turn absolute path into the right lib path (lib is NOT in webpack output path, so need to use '../')
99
- let outputPath = absoluteFilename.replace(process.cwd(), '').replace('/src/', '../lib/');
100
- // console.log(chalk.blueBright(outputPath));
101
- return Promise.resolve(outputPath);
102
- },
103
- noErrorOnMissing: true,
104
- },
105
- ],
106
- }),
107
- ];
108
- if (config.debug) {
109
- plugins.push(new watch_run_1.default());
110
- }
111
- if (config.afterBuildCommand || config.afterFirstBuildCommand) {
112
- let executedFirstCommand = false;
113
- plugins.push({
114
- apply: (compiler) => {
115
- compiler.hooks.afterEmit.tap('AfterEmitPlugin', (compilation) => {
116
- if (config.afterBuildCommand) {
117
- exec(config.afterBuildCommand, (err, stdout, stderr) => {
118
- if (stdout)
119
- process.stdout.write(stdout);
120
- if (stderr)
121
- process.stderr.write(stderr);
122
- });
123
- }
124
- if (config.afterFirstBuildCommand && !executedFirstCommand) {
125
- executedFirstCommand = true;
126
- exec(config.afterFirstBuildCommand, (err, stdout, stderr) => {
127
- if (stdout)
128
- process.stdout.write(stdout);
129
- if (stderr)
130
- process.stderr.write(stderr);
131
- });
132
- }
133
- });
134
- },
135
- });
136
- }
137
- if (config.analyse) {
138
- plugins.push(new BundleAnalyzerPlugin());
139
- }
140
- if ((es6 || config.declarations === true) && !config.declarations === false) {
141
- plugins.push(new declaration_plugin_1.default({
142
- out: (config.filename ? config.filename : cleanModuleName) + '.d.ts',
143
- root: config.outputPath ? config.outputPath : './lib/',
144
- debug: 'debug' in config ? config.debug : false,
145
- }));
146
- }
147
- // var resolvePlugins = [
148
- // new TsconfigPathsPlugin({
149
- // configFile: configFile,
150
- // silent: true,
54
+ if (!config.externals) config.externals = {};
55
+ if (!config.internals) config.internals = [];
56
+ var watch = config.watch;
57
+ var productionMode = nodeProduction || config.productionMode;
58
+ var es5 = config.target == 'es5';
59
+ var es6 = config.target == 'es6';
60
+ //remove the scope (used for filenames for example)
61
+ var cleanModuleName = moduleName.replace(/@[\w\-]+\//, '');
62
+ var configFile;
63
+ if (es5 && fs.existsSync('tsconfig-es5.json')) {
64
+ configFile = 'tsconfig-es5.json';
65
+ } else {
66
+ configFile = 'tsconfig.json';
67
+ }
68
+ if (!fs.existsSync(configFile)) {
69
+ (0, utils_1.warn)('Cannot find ' + configFile);
70
+ process.exit();
71
+ }
72
+ let tsConfig = JSON.parse(fs.readFileSync(configFile));
73
+ var plugins = [
74
+ // new webpack.DefinePlugin({
75
+ // 'process.env.BROWSER': JSON.stringify(true),
76
+ // 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
151
77
  // }),
152
- // ];
153
- var aliases = config.alias || {};
154
- let postcssPlugins = [];
155
- if (!config.cssMode) {
156
- config.cssMode = 'mixed';
157
- }
158
- if (config.cssMode === 'scss-modules' || config.cssMode === 'scss' || config.cssMode === 'mixed') {
159
- postcssPlugins = postcssPlugins.concat(['postcss-preset-env', productionMode && 'cssnano']);
160
- //we once had:
161
- // 'postcss-import': {},
162
- // // 'postcss-cssnext': {},
163
- // 'postcss-nested': {},
164
- // // "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
165
- if (config.cssMode === 'scss-modules' || config.cssMode === 'mixed') {
166
- postcssPlugins.push([
167
- 'postcss-modules',
168
- {
169
- generateScopedName: utils_1.generateScopedName.bind(null, moduleName),
170
- globalModulePaths: [/tailwind/, /tailwindcss/, config.cssGlobalModulePaths].filter(Boolean),
171
- },
172
- ]);
173
- }
174
- }
175
- if (config.cssMode === 'tailwind' || config.cssMode === 'mixed') {
176
- let lincdPackagePaths;
177
- //IF this package is including sources from another lincd package in its bundle (usually not the case)
178
- if (config.internals) {
179
- //THEN make sure that we also look for tailwind classes in those packages
180
- //pass the list of internal packages, or if all, pass null because it will look up all the package.json:dependencies
181
- lincdPackagePaths = getLincdPackagePaths(config.internals !== '*' ? config.internals : null).map((path) => {
182
- return path + '/lib/**/*.{js,mjs}';
183
- });
184
- }
185
- // console.log(chalk.blueBright('tailwind content: ')+chalk.magenta(['./frontend/src/**/*.{tsx,ts}',...lincdPackagePaths]));
186
- postcssPlugins.push([
187
- 'tailwindcss',
188
- {
189
- content: ['./src/**/*.{tsx,ts}', ...lincdPackagePaths],
190
- safelist: productionMode
191
- ? {}
192
- : {
193
- //in development mode we allow all classes here, so that you can easily develop
194
- pattern: /./,
195
- variants: ['sm', 'md', 'lg', 'xl', '2xl'],
196
- },
197
- theme: {
198
- extend: {
199
- colors: (0, utils_1.getLinkedTailwindColors)(),
200
- },
201
- },
202
- plugins: [
203
- tailwindPlugin(function ({ addBase, config }) {
204
- //we can use LINCD CSS variables for default font color, size etc.
205
- // addBase({
206
- // 'h1': { fontSize: config('theme.fontSize.2xl') },
207
- // 'h2': { fontSize: config('theme.fontSize.xl') },
208
- // 'h3': { fontSize: config('theme.fontSize.lg') },
209
- // })
210
- }),
211
- ],
212
- },
213
- ]);
214
- }
215
- let rules = [
78
+ // new webpack.NoEmitOnErrorsPlugin(),
79
+ // new ExtractTextPlugin(config.cssFileName ? config.cssFileName : cleanModuleName + '.css'),
80
+ new MiniCssExtractPlugin({
81
+ // linkType: false,
82
+ filename: config.cssFileName ? config.cssFileName : cleanModuleName + '.css',
83
+ }),
84
+ //currently not compatible with webpack 5
85
+ // new WebpackLicencePlugin({
86
+ // excludedPackageTest: (packageName, version) => {
87
+ // return packageName.indexOf('lincd') !== -1;
88
+ // },
89
+ // }),
90
+ //NOTE: grunt comes with a copy task, which is ran during `yarn lincd build` but cannot run during `yarn lincd dev`
91
+ //so here we ALSO copy the same files to cover dev flow
92
+ new CopyPlugin({
93
+ patterns: [
216
94
  {
217
- test: /\.(scss|css)$/,
218
- use: [
219
- MiniCssExtractPlugin.loader,
220
- {
221
- loader: 'css-loader',
222
- options: {
223
- url: false,
224
- },
225
- },
226
- {
227
- loader: 'postcss-loader',
228
- options: {
229
- postcssOptions: {
230
- plugins: postcssPlugins,
231
- },
232
- },
233
- },
234
- {
235
- loader: 'sass-loader',
236
- options: { sourceMap: true },
237
- },
238
- ],
95
+ from: 'src/**/*.scss',
96
+ to({context, absoluteFilename}) {
97
+ // console.log(chalk.magenta(context),chalk.magenta(absoluteFilename),process.cwd());
98
+ //turn absolute path into the right lib path (lib is NOT in webpack output path, so need to use '../')
99
+ let outputPath = absoluteFilename.replace(process.cwd(), '').replace('/src/', '../lib/');
100
+ // console.log(chalk.blueBright(outputPath));
101
+ return Promise.resolve(outputPath);
102
+ },
103
+ noErrorOnMissing: true,
239
104
  },
240
- // {
241
- // test: /\.(ts|tsx)$/,
242
- // exclude: /node_modules/,
243
- // //include: [path.join(process.cwd(),"frontend")], // only bundle files in this directory
244
- // use: {
245
- // loader: "babel-loader", // cf. .babelrc.json in this folder and browser list in package.json
246
- // options: {
247
- // // plugins: productionMode ? [] : ["react-refresh/babel"],
248
- // cacheCompression: false,
249
- // cacheDirectory: true,
250
- // presets: [
251
- // "@babel/preset-env",
252
- // ["@babel/preset-react", {"runtime": "automatic"}],
253
- // "@babel/preset-typescript",
254
- // ],
255
- // plugins: [
256
- // "@babel/plugin-transform-runtime",
257
- // ["@babel/plugin-proposal-decorators",{
258
- // decoratorsBeforeExport:true
259
- // }]
260
- // ],
261
- // },
262
- // },
263
- // },
105
+ ],
106
+ }),
107
+ ];
108
+ if (config.debug) {
109
+ plugins.push(new watch_run_1.default());
110
+ }
111
+ if (config.afterBuildCommand || config.afterFirstBuildCommand) {
112
+ let executedFirstCommand = false;
113
+ plugins.push({
114
+ apply: (compiler) => {
115
+ compiler.hooks.afterEmit.tap('AfterEmitPlugin', (compilation) => {
116
+ if (config.afterBuildCommand) {
117
+ exec(config.afterBuildCommand, (err, stdout, stderr) => {
118
+ if (stdout) process.stdout.write(stdout);
119
+ if (stderr) process.stderr.write(stderr);
120
+ });
121
+ }
122
+ if (config.afterFirstBuildCommand && !executedFirstCommand) {
123
+ executedFirstCommand = true;
124
+ exec(config.afterFirstBuildCommand, (err, stdout, stderr) => {
125
+ if (stdout) process.stdout.write(stdout);
126
+ if (stderr) process.stderr.write(stderr);
127
+ });
128
+ }
129
+ });
130
+ },
131
+ });
132
+ }
133
+ if (config.analyse) {
134
+ plugins.push(new BundleAnalyzerPlugin());
135
+ }
136
+ if ((es6 || config.declarations === true) && !config.declarations === false) {
137
+ plugins.push(
138
+ new declaration_plugin_1.default({
139
+ out: (config.filename ? config.filename : cleanModuleName) + '.d.ts',
140
+ root: config.outputPath ? config.outputPath : './lib/',
141
+ debug: 'debug' in config ? config.debug : false,
142
+ }),
143
+ );
144
+ }
145
+ // var resolvePlugins = [
146
+ // new TsconfigPathsPlugin({
147
+ // configFile: configFile,
148
+ // silent: true,
149
+ // }),
150
+ // ];
151
+ var aliases = config.alias || {};
152
+ let postcssPlugins = [];
153
+ if (!config.cssMode) {
154
+ config.cssMode = 'mixed';
155
+ }
156
+ if (config.cssMode === 'scss-modules' || config.cssMode === 'scss' || config.cssMode === 'mixed') {
157
+ postcssPlugins = postcssPlugins.concat(['postcss-preset-env', productionMode && 'cssnano']);
158
+ //we once had:
159
+ // 'postcss-import': {},
160
+ // // 'postcss-cssnext': {},
161
+ // 'postcss-nested': {},
162
+ // // "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
163
+ if (config.cssMode === 'scss-modules' || config.cssMode === 'mixed') {
164
+ postcssPlugins.push([
165
+ 'postcss-modules',
264
166
  {
265
- test: /\.tsx?$/,
266
- use: [
267
- {
268
- loader: 'ts-loader?' +
269
- JSON.stringify(Object.assign({ configFile: configFile, compilerOptions: {
270
- declaration: !es5,
271
- /*
272
- for webpack we overwrite the module settings of the modules' tsconfig file
273
- because we NEED esnext for code splitting. But the VM we currently use for the registry does not support esnext modules
274
- */
275
- module: 'esnext',
276
- moduleResolution: 'node',
277
- } }, config.tsConfigOverwrites)),
278
- },
279
- ],
167
+ generateScopedName: utils_1.generateScopedName.bind(null, moduleName),
168
+ globalModulePaths: [/tailwind/, /tailwindcss/, config.cssGlobalModulePaths].filter(Boolean),
280
169
  },
281
- // {
282
- // enforce: 'pre',
283
- // test: /\.js$/,
284
- // use: [
285
- // {
286
- // loader: 'source-map-loader',
287
- // },
288
- // ],
289
- // },
290
- ];
291
- if (es5 && config.internalsources && config.internalsources.length > 0) {
292
- //usually a module that transpiles to es5 will only have es5 code in the bundle.
293
- //however a module that INTERNALISES other dacore modules will directly include es6 code from @dacore/other_modules/lib
294
- //which eventually results in an import of @dacore/core being bundled as 'const =', which trips up old browsers
295
- //so we fix that here by just referring directly to the typescript source instead of the transpiled js for internalised modules
296
- //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
297
- //so that means internalised modules need to be LOCALLY AVAILABLE with yarn workspaces
298
- plugins.push(new webpack.NormalModuleReplacementPlugin(/lincd\/lib\//, (resource, match) => {
299
- let moduleName = resource.request.match(/lincd\/lib\//)[1];
300
- if (config.internalsources.indexOf(moduleName) !== -1) {
301
- console.log(colors.magenta('internal sources + ES5: Replacing /lib/ with /src/ for source-internalised module ' + moduleName));
302
- resource.request = resource.request.replace('/lib/', '/src/');
303
- console.log(colors.magenta('internal sources + ES5: ' + resource.request));
304
- 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."));
305
- }
306
- }));
170
+ ]);
307
171
  }
308
- return {
309
- entry: config.entry ? config.entry : tsConfig.files ? tsConfig.files : './src/index.ts',
310
- output: {
311
- filename: (config.filename ? config.filename : cleanModuleName) + (es5 ? '.es5' : '') + '.js',
312
- path: path.resolve(process.cwd(), config.bundlePath || 'dist'),
313
- devtoolModuleFilenameTemplate: moduleName + '/[resource-path]',
314
- },
315
- devtool: productionMode ? 'source-map' : 'cheap-module-source-map',
316
- // devtool: productionMode ? 'cheap-source-map' : 'cheap-source-map',
317
- mode: productionMode ? 'production' : 'development',
318
- //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
319
- // node: {
320
- // fs: 'empty',
321
- // child_process: 'empty',
322
- // },
323
- resolve: {
324
- extensions: ['.webpack.js', '.js', '.ts', '.tsx', '.json'],
325
- alias: aliases,
326
- // plugins: resolvePlugins,
327
- fallback: { crypto: false },
328
- },
329
- resolveLoader: {
330
- modules: [
331
- path.join(__dirname, 'plugins'),
332
- path.join(__dirname, 'node_modules'),
333
- 'node_modules',
334
- ],
335
- },
336
- optimization: {
337
- minimize: productionMode,
338
- minimizer: [
339
- new TerserPlugin({
340
- extractComments: {
341
- condition: /^\**!|@preserve|@license|@cc_on/i,
342
- banner: (licenseFile) => {
343
- return `License information can be found in ${licenseFile} and oss-licences.json`;
344
- },
345
- },
346
- }),
347
- ],
172
+ }
173
+ if (config.cssMode === 'tailwind' || config.cssMode === 'mixed') {
174
+ let lincdPackagePaths;
175
+ //IF this package is including sources from another lincd package in its bundle (usually not the case)
176
+ if (config.internals) {
177
+ //THEN make sure that we also look for tailwind classes in those packages
178
+ //pass the list of internal packages, or if all, pass null because it will look up all the package.json:dependencies
179
+ lincdPackagePaths = getLincdPackagePaths(config.internals !== '*' ? config.internals : null).map((path) => {
180
+ return path + '/lib/**/*.{js,mjs}';
181
+ });
182
+ }
183
+ // console.log(chalk.blueBright('tailwind content: ')+chalk.magenta(['./frontend/src/**/*.{tsx,ts}',...lincdPackagePaths]));
184
+ postcssPlugins.push([
185
+ 'tailwindcss',
186
+ {
187
+ content: ['./src/**/*.{tsx,ts}', ...lincdPackagePaths],
188
+ safelist: productionMode
189
+ ? {}
190
+ : {
191
+ //in development mode we allow all classes here, so that you can easily develop
192
+ pattern: /./,
193
+ variants: ['sm', 'md', 'lg', 'xl', '2xl'],
194
+ },
195
+ theme: {
196
+ extend: {
197
+ colors: (0, utils_1.getLinkedTailwindColors)(),
198
+ },
348
199
  },
349
- watch: watch,
350
- watchOptions: {
351
- ignored: ['**/*.d.ts', '**/*.js.map', '**/*.scss.json'],
352
- aggregateTimeout: 500,
200
+ plugins: [
201
+ tailwindPlugin(function ({addBase, config}) {
202
+ //we can use LINCD CSS variables for default font color, size etc.
203
+ // addBase({
204
+ // 'h1': { fontSize: config('theme.fontSize.2xl') },
205
+ // 'h2': { fontSize: config('theme.fontSize.xl') },
206
+ // 'h3': { fontSize: config('theme.fontSize.lg') },
207
+ // })
208
+ }),
209
+ ],
210
+ },
211
+ ]);
212
+ }
213
+ let rules = [
214
+ {
215
+ test: /\.(scss|css)$/,
216
+ use: [
217
+ MiniCssExtractPlugin.loader,
218
+ {
219
+ loader: 'css-loader',
220
+ options: {
221
+ url: false,
222
+ },
353
223
  },
354
- module: {
355
- rules,
224
+ {
225
+ loader: 'postcss-loader',
226
+ options: {
227
+ postcssOptions: {
228
+ plugins: postcssPlugins,
229
+ },
230
+ },
356
231
  },
357
- //See plugins/externalise-modules.ts We're passing in a function here that determines what to exclude from the bundle and what not
358
- //See also https://webpack.js.org/configuration/externals/
359
- externals: (0, externalise_modules_1.default)(config, es5),
360
- plugins: plugins,
361
- stats: {
362
- errorDetails: true,
363
- chunks: false,
364
- children: true,
365
- version: true,
366
- hash: false,
367
- entrypoints: false,
368
- modules: false,
232
+ {
233
+ loader: 'sass-loader',
234
+ options: {sourceMap: true},
369
235
  },
370
- //hide some info from output when in watch mode to keep it succinct
371
- //stats:{chunks:!watch,version:!watch}//hide some info from output when in watch mode to keep it succinct
372
- cache: {
373
- // https://webpack.js.org/configuration/other-options/#cache
374
- type: 'filesystem',
375
- // cacheDirectory: path.resolve(process.cwd(),"node_modules",".cache","webpack"),
376
- // name: "lincd-webpack-cache",
236
+ ],
237
+ },
238
+ // {
239
+ // test: /\.(ts|tsx)$/,
240
+ // exclude: /node_modules/,
241
+ // //include: [path.join(process.cwd(),"frontend")], // only bundle files in this directory
242
+ // use: {
243
+ // loader: "babel-loader", // cf. .babelrc.json in this folder and browser list in package.json
244
+ // options: {
245
+ // // plugins: productionMode ? [] : ["react-refresh/babel"],
246
+ // cacheCompression: false,
247
+ // cacheDirectory: true,
248
+ // presets: [
249
+ // "@babel/preset-env",
250
+ // ["@babel/preset-react", {"runtime": "automatic"}],
251
+ // "@babel/preset-typescript",
252
+ // ],
253
+ // plugins: [
254
+ // "@babel/plugin-transform-runtime",
255
+ // ["@babel/plugin-proposal-decorators",{
256
+ // decoratorsBeforeExport:true
257
+ // }]
258
+ // ],
259
+ // },
260
+ // },
261
+ // },
262
+ {
263
+ test: /\.tsx?$/,
264
+ use: [
265
+ {
266
+ loader:
267
+ 'ts-loader?' +
268
+ JSON.stringify(
269
+ Object.assign(
270
+ {
271
+ configFile: configFile,
272
+ compilerOptions: {
273
+ declaration: !es5,
274
+ /*
275
+ for webpack we overwrite the module settings of the modules' tsconfig file
276
+ because we NEED esnext for code splitting. But the VM we currently use for the registry does not support esnext modules
277
+ */
278
+ module: 'esnext',
279
+ moduleResolution: 'node',
280
+ },
281
+ },
282
+ config.tsConfigOverwrites,
283
+ ),
284
+ ),
377
285
  },
378
- };
286
+ ],
287
+ },
288
+ // {
289
+ // enforce: 'pre',
290
+ // test: /\.js$/,
291
+ // use: [
292
+ // {
293
+ // loader: 'source-map-loader',
294
+ // },
295
+ // ],
296
+ // },
297
+ ];
298
+ if (es5 && config.internalsources && config.internalsources.length > 0) {
299
+ //usually a module that transpiles to es5 will only have es5 code in the bundle.
300
+ //however a module that INTERNALISES other dacore modules will directly include es6 code from @dacore/other_modules/lib
301
+ //which eventually results in an import of @dacore/core being bundled as 'const =', which trips up old browsers
302
+ //so we fix that here by just referring directly to the typescript source instead of the transpiled js for internalised modules
303
+ //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
304
+ //so that means internalised modules need to be LOCALLY AVAILABLE with yarn workspaces
305
+ plugins.push(
306
+ new webpack.NormalModuleReplacementPlugin(/lincd\/lib\//, (resource, match) => {
307
+ let moduleName = resource.request.match(/lincd\/lib\//)[1];
308
+ if (config.internalsources.indexOf(moduleName) !== -1) {
309
+ console.log(
310
+ colors.magenta(
311
+ 'internal sources + ES5: Replacing /lib/ with /src/ for source-internalised module ' + moduleName,
312
+ ),
313
+ );
314
+ resource.request = resource.request.replace('/lib/', '/src/');
315
+ console.log(colors.magenta('internal sources + ES5: ' + resource.request));
316
+ console.log(
317
+ colors.red(
318
+ "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.",
319
+ ),
320
+ );
321
+ }
322
+ }),
323
+ );
324
+ }
325
+ return {
326
+ entry: config.entry ? config.entry : tsConfig.files ? tsConfig.files : './src/index.ts',
327
+ output: {
328
+ filename: (config.filename ? config.filename : cleanModuleName) + (es5 ? '.es5' : '') + '.js',
329
+ path: path.resolve(process.cwd(), config.bundlePath || 'dist'),
330
+ devtoolModuleFilenameTemplate: moduleName + '/[resource-path]',
331
+ },
332
+ devtool: productionMode ? 'source-map' : 'cheap-module-source-map',
333
+ // devtool: productionMode ? 'cheap-source-map' : 'cheap-source-map',
334
+ mode: productionMode ? 'production' : 'development',
335
+ //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
336
+ // node: {
337
+ // fs: 'empty',
338
+ // child_process: 'empty',
339
+ // },
340
+ resolve: {
341
+ extensions: ['.webpack.js', '.js', '.ts', '.tsx', '.json'],
342
+ alias: aliases,
343
+ // plugins: resolvePlugins,
344
+ fallback: {crypto: false},
345
+ },
346
+ resolveLoader: {
347
+ modules: [path.join(__dirname, 'plugins'), path.join(__dirname, 'node_modules'), 'node_modules'],
348
+ },
349
+ optimization: {
350
+ minimize: productionMode,
351
+ minimizer: [
352
+ new TerserPlugin({
353
+ extractComments: {
354
+ condition: /^\**!|@preserve|@license|@cc_on/i,
355
+ banner: (licenseFile) => {
356
+ return `License information can be found in ${licenseFile} and oss-licences.json`;
357
+ },
358
+ },
359
+ }),
360
+ ],
361
+ },
362
+ watch: watch,
363
+ watchOptions: {
364
+ ignored: ['**/*.d.ts', '**/*.js.map', '**/*.scss.json'],
365
+ aggregateTimeout: 500,
366
+ },
367
+ module: {
368
+ rules,
369
+ },
370
+ //See plugins/externalise-modules.ts We're passing in a function here that determines what to exclude from the bundle and what not
371
+ //See also https://webpack.js.org/configuration/externals/
372
+ externals: (0, externalise_modules_1.default)(config, es5),
373
+ plugins: plugins,
374
+ stats: {
375
+ errorDetails: true,
376
+ chunks: false,
377
+ children: true,
378
+ version: true,
379
+ hash: false,
380
+ entrypoints: false,
381
+ modules: false,
382
+ },
383
+ //hide some info from output when in watch mode to keep it succinct
384
+ //stats:{chunks:!watch,version:!watch}//hide some info from output when in watch mode to keep it succinct
385
+ cache: {
386
+ // https://webpack.js.org/configuration/other-options/#cache
387
+ type: 'filesystem',
388
+ // cacheDirectory: path.resolve(process.cwd(),"node_modules",".cache","webpack"),
389
+ // name: "lincd-webpack-cache",
390
+ },
391
+ };
379
392
  }
393
+
380
394
  exports.generateWebpackConfig = generateWebpackConfig;