lincd-cli 0.2.46 → 0.2.48

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