ko 5.2.1 → 5.2.2

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.
Files changed (81) hide show
  1. package/README.md +2 -128
  2. package/lib/actions/build.js +74 -0
  3. package/lib/actions/creator.js +42 -0
  4. package/lib/actions/dev.js +110 -0
  5. package/lib/cli.js +41 -0
  6. package/lib/interfaces.js +2 -0
  7. package/lib/utils/config.js +42 -0
  8. package/lib/utils/config.test.js +30 -0
  9. package/lib/webpack/index.js +55 -0
  10. package/lib/webpack/loaders/asset.js +19 -0
  11. package/lib/webpack/loaders/index.js +12 -0
  12. package/lib/webpack/loaders/script.js +59 -0
  13. package/lib/webpack/loaders/style.js +72 -0
  14. package/lib/webpack/plugins.js +61 -0
  15. package/package.json +43 -85
  16. package/{preinstall.js → scripts/preinstall.js} +6 -5
  17. package/.eslintignore +0 -3
  18. package/.eslintrc.js +0 -96
  19. package/.github/workflows/auto-publish.yml +0 -32
  20. package/.github/workflows/ci.yml +0 -67
  21. package/.husky/pre-commit +0 -4
  22. package/.prettierignore +0 -5
  23. package/CHANGELOG.md +0 -115
  24. package/bin/ko-build.js +0 -30
  25. package/bin/ko-create.js +0 -14
  26. package/bin/ko-dev.js +0 -31
  27. package/bin/ko-init.js +0 -14
  28. package/bin/ko-install.js +0 -27
  29. package/bin/ko-lint.js +0 -18
  30. package/bin/ko-move.js +0 -14
  31. package/bin/ko-preview.js +0 -27
  32. package/bin/ko-swagger.js +0 -41
  33. package/bin/ko.js +0 -29
  34. package/commitlint.config.js +0 -7
  35. package/config/defaultPaths.js +0 -26
  36. package/config/lint/getEslintConf.js +0 -23
  37. package/config/lint/getPrettierConf.js +0 -14
  38. package/config/lint/index.js +0 -14
  39. package/config/webpack/base.js +0 -77
  40. package/config/webpack/devServer.js +0 -39
  41. package/config/webpack/index.js +0 -63
  42. package/config/webpack/loaders.js +0 -142
  43. package/config/webpack/plugins.js +0 -70
  44. package/constants/default.js +0 -7
  45. package/constants/env.js +0 -7
  46. package/jest.config.js +0 -44
  47. package/prettier.config.js +0 -8
  48. package/script/build.js +0 -23
  49. package/script/create.js +0 -31
  50. package/script/dev.js +0 -96
  51. package/script/init.js +0 -129
  52. package/script/install.js +0 -91
  53. package/script/lint.js +0 -24
  54. package/script/move.js +0 -38
  55. package/script/preview.js +0 -22
  56. package/script/swagger.js +0 -239
  57. package/template/index.html +0 -0
  58. package/template/pageTemplate.mustache +0 -21
  59. package/template/pageTemplateTS.mustache +0 -29
  60. package/template/restful.hbs +0 -14
  61. package/template/restfulTemplate.mustache +0 -12
  62. package/template/routerConfTemplate.mustache +0 -15
  63. package/template/styleTemplate.mustache +0 -3
  64. package/template/tsconfig.json +0 -22
  65. package/util/__tests__/file.test.js +0 -16
  66. package/util/__tests__/fileService.test.js +0 -101
  67. package/util/__tests__/index.test.js +0 -51
  68. package/util/__tests__/userConfig.test.js +0 -83
  69. package/util/__tests__/verifyHtml.test.js +0 -81
  70. package/util/createComp.js +0 -71
  71. package/util/createPage.js +0 -141
  72. package/util/defaultData.js +0 -64
  73. package/util/file.js +0 -9
  74. package/util/fileService.js +0 -55
  75. package/util/index.js +0 -25
  76. package/util/prepareUrl.js +0 -69
  77. package/util/program.js +0 -20
  78. package/util/request.js +0 -18
  79. package/util/stdout.js +0 -36
  80. package/util/userConfig.js +0 -40
  81. package/util/verifyHtml.js +0 -63
package/bin/ko-build.js DELETED
@@ -1,30 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- // set NODE_ENV to production
5
- const { PROD } = require('../constants/env');
6
- process.env.NODE_ENV = PROD;
7
-
8
- const colors = require('colors');
9
- const { program, attachOptions } = require('../util/program');
10
- const { inProcess } = require('../util/stdout');
11
- const build = require('../script/build');
12
-
13
- program
14
- .option('--hash', 'output file name with hash')
15
- .option('-t,--ts,--typescript', 'support typescript')
16
- .option('-e, --env [env]', 'user defined building environment')
17
- .parse(process.argv);
18
-
19
- attachOptions(program);
20
-
21
- try {
22
- const inProcessConf = {
23
- initStr: 'ko build start!',
24
- spinStr: 'building...',
25
- process: build,
26
- };
27
- inProcess(inProcessConf);
28
- } catch (ex) {
29
- console.log(colors.red('ko build failed:', ex));
30
- }
package/bin/ko-create.js DELETED
@@ -1,14 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- 'use strict';
4
- const program = require('commander');
5
- const colors = require('colors');
6
- const create = require('../script/create');
7
- const log = console.log;
8
- program.option('-f,--flag', '支持typescript模版').parse(process.argv);
9
-
10
- try {
11
- create(program);
12
- } catch (err) {
13
- log(colors.red)('创建失败,请检查参数是否有误。');
14
- }
package/bin/ko-dev.js DELETED
@@ -1,31 +0,0 @@
1
- #! /usr/bin/env node
2
- 'use strict';
3
-
4
- // set NODE_ENV to development
5
- const { DEV } = require('../constants/env');
6
- process.env.NODE_ENV = DEV;
7
-
8
- const colors = require('colors');
9
- const { program, attachOptions } = require('../util/program');
10
- const { inProcess } = require('../util/stdout');
11
- const dev = require('../script/dev');
12
-
13
- program
14
- .option('-p, --port <port>', 'server start on which port', parseInt)
15
- .option('--host <host>', 'specify a host to use')
16
- .option('-t, --ts', 'support typescript')
17
- .option('-a,--analyzer', 'support building analyzer')
18
- .parse(process.argv);
19
-
20
- attachOptions(program);
21
-
22
- try {
23
- const inProcessConf = {
24
- initStr: 'ko dev server start!',
25
- spinStr: 'compiling...',
26
- process: dev,
27
- };
28
- inProcess(inProcessConf);
29
- } catch (ex) {
30
- console.log(colors.red('process init failed:'), ex);
31
- }
package/bin/ko-init.js DELETED
@@ -1,14 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- 'use strict';
4
- const program = require('commander');
5
- const colors = require('colors');
6
- const init = require('../script/init');
7
- const log = console.log;
8
- program.option('-t,--ts', '支持typescript模版').parse(process.argv);
9
-
10
- try {
11
- init(program);
12
- } catch (err) {
13
- log(colors.red)('服务启动失败,请检查package中dependencies依赖包');
14
- }
package/bin/ko-install.js DELETED
@@ -1,27 +0,0 @@
1
- const program = require('commander');
2
- const attachToEnv = require('../util/attachToEnv');
3
- const install = require('../script/install');
4
- const colors = require('colors');
5
- const log = console.log;
6
- const ora = require('ora');
7
- program
8
- .option('-n,--name <name>', '待安装组件名')
9
- .option('-p,--path <path>', '安装绝对路径')
10
- .parse(process.argv);
11
- attachToEnv(program); // 当前终端命令假如环境变量,避免权限无法执行问题;
12
-
13
- try {
14
- const spinner = ora('install ').start();
15
- setTimeout(() => {
16
- spinner.color = 'yellow';
17
- spinner.text = 'complie ...';
18
- }, 100);
19
- install(program);
20
- spinner.stop();
21
- } catch (err) {
22
- log(
23
- [` - Tip: ${colors.red('安装组件失败,请检查组件名或者网络')}`].join(
24
- '\n'
25
- )
26
- );
27
- }
package/bin/ko-lint.js DELETED
@@ -1,18 +0,0 @@
1
- #! /usr/bin/env node
2
- 'use strict';
3
-
4
- const colors = require('colors');
5
- const { inProcess } = require('../util/stdout');
6
- const lint = require('../script/lint');
7
-
8
- // TODO: support user defined eslint & prettier config with cli options
9
- try {
10
- const inProcessConf = {
11
- initStr: 'ko lint start!',
12
- spinStr: 'compiling...',
13
- process: lint,
14
- };
15
- inProcess(inProcessConf);
16
- } catch (err) {
17
- console.log(colors.red('process init failed:'), err);
18
- }
package/bin/ko-move.js DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- 'use strict';
4
- const program = require('commander');
5
- const colors = require('colors');
6
- const move = require('../script/move');
7
-
8
- program.option('-d, --dir <dir>', '自定义目录名').parse(process.argv);
9
-
10
- try {
11
- move();
12
- } catch (err) {
13
- console.log(colors.red('移动文件失败,请重试。'));
14
- }
package/bin/ko-preview.js DELETED
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env node
2
- /*
3
- * @Description: 文件
4
- * @version: 1.0.0
5
- * @Company: 袋鼠云
6
- * @Author: Charles
7
- * @Date: 2018-12-19 15:31:48
8
- * @LastEditors: Charles
9
- * @LastEditTime: 2019-11-21 09:51:47
10
- */
11
- 'use strict';
12
- const program = require('commander');
13
- const log = console.log;
14
- const colors = require('colors');
15
- const preview = require('../script/preview');
16
-
17
- program
18
- .option('-p, --port <port>', '预览端口号')
19
- .option('-i, --ip <address>', '指定ip')
20
- .option('-d, --dist <dist>', '预览文件目录[相对路径 如./]')
21
- .parse(process.argv);
22
-
23
- try {
24
- preview(program);
25
- } catch (err) {
26
- log(colors.red('启动失败,请检查端口是否被占用' + err));
27
- }
package/bin/ko-swagger.js DELETED
@@ -1,41 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- const program = require('commander');
4
- const colors = require('colors');
5
- const inquirer = require('inquirer');
6
- const { resolveApp } = require('../config/defaultPaths');
7
- const swagger = require('../script/swagger.js');
8
- const logs = console.log;
9
- program
10
- .option('-p, --path', '自定义生成目录')
11
- .option('-t, --ts', '支持typescript')
12
- .parse(process.argv);
13
-
14
- try {
15
- const question = [
16
- {
17
- type: 'Input',
18
- name: 'swagger',
19
- message: '请输入swagger地址(如:http://xxxxx/swagger-ui.html#/)',
20
- },
21
- ];
22
- program.path &&
23
- question.push({
24
- type: 'Input',
25
- name: 'path',
26
- message: '请输入生成目录(绝对路径)',
27
- default: '',
28
- });
29
- inquirer.prompt(question).then((answers) => {
30
- if (answers.swagger == '') {
31
- logs(colors.red('请输入swagger地址'));
32
- } else {
33
- if (!answers.path || answers.path == '') {
34
- answers.path = resolveApp('src/service/');
35
- }
36
- swagger(answers.swagger, answers.path, program.ts);
37
- }
38
- });
39
- } catch (err) {
40
- logs(colors.red(err || '服务启动失败'));
41
- }
package/bin/ko.js DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- const { program } = require('../util/program');
5
- const pkg = require('../package.json');
6
-
7
- program
8
- .description('building tools based on webpack')
9
- .version(pkg.version, '-v, --version')
10
- .usage('<command> [options]')
11
- .command('init', 'init scaffold')
12
- .command('create', 'create web component')
13
- .command('build', 'build project')
14
- .command('dev', 'start server')
15
- .command('dll', 'build dll')
16
- .command('preview', 'browser app')
17
- .command('install', 'install component')
18
- .command('move', 'move to gh-pages')
19
- .command('swagger', 'generate swagger api')
20
- .command('createPage', 'create page and config router')
21
- .command('createComp', 'create component')
22
- .command('lint', 'lint project files');
23
-
24
- program.parse(process.argv);
25
-
26
- const subCmd = program.args[0];
27
- if (!subCmd) {
28
- program.help();
29
- }
@@ -1,7 +0,0 @@
1
- module.exports = {
2
- extends: ['@commitlint/config-conventional'],
3
- rules: {
4
- 'type-case': [2, 'always', 'lower-case'],
5
- 'scope-case': [0, 'always'],
6
- },
7
- };
@@ -1,26 +0,0 @@
1
- const { resolve } = require('path');
2
- const userHome = require('user-home');
3
- const { getFileRealPath } = require('../util/file');
4
-
5
- module.exports = {
6
- appBuild: getFileRealPath('build'),
7
- appDist: getFileRealPath('dist'),
8
- appDll: getFileRealPath('dll'),
9
- appPublic: getFileRealPath('public'),
10
- appHtml: getFileRealPath('public/index.html'),
11
- appConfig: getFileRealPath('public/config'),
12
- appPkg: getFileRealPath('package.json'),
13
- appAsset: getFileRealPath('dll/bundle.json'),
14
- appSrc: getFileRealPath('src'),
15
- appTsConfig: getFileRealPath('tsconfig.json'),
16
- appModules: getFileRealPath('node_modules'),
17
- appGhPage: getFileRealPath('gh-pages'),
18
- userCacheRepoDir: resolve(userHome, '.ko-scaffold'), // TODO: refactor this
19
- prettierignore:
20
- getFileRealPath('.prettierignore') ||
21
- resolve(__dirname, '../.prettierignore'),
22
- eslintignore:
23
- getFileRealPath('.eslintignore') || resolve(__dirname, '../.eslintignore'),
24
- appDirectory: process.cwd(),
25
- scaffoldConfUrl: 'https://dtux-kangaroo.github.io/ko-config/ko-script.json',
26
- };
@@ -1,23 +0,0 @@
1
- const mergeOptions = require('merge-options');
2
- const { eslint } = require('../../util/userConfig');
3
- const defaultEslintConf = require('../../.eslintrc');
4
- /**
5
- * eslint default config, user defined config file can override it
6
- * @ref: https://eslint.org/docs/rules/
7
- */
8
-
9
- function getLintConf() {
10
- if (typeof eslint === 'string') {
11
- return eslint ? require(eslint) : {};
12
- } else {
13
- return eslint;
14
- }
15
- }
16
-
17
- const config = mergeOptions.call(
18
- { concatArrays: true },
19
- {},
20
- defaultEslintConf,
21
- getLintConf()
22
- );
23
- module.exports = config;
@@ -1,14 +0,0 @@
1
- const mergeOptions = require('merge-options');
2
- const { prettier } = require('../../util/userConfig');
3
- const defaultPrettierConf = require('../../prettier.config');
4
-
5
- function getLintConf() {
6
- if (typeof prettier === 'string') {
7
- return prettier ? require(prettier) : {};
8
- } else {
9
- return prettier;
10
- }
11
- }
12
-
13
- const config = mergeOptions({}, defaultPrettierConf, getLintConf());
14
- module.exports = config;
@@ -1,14 +0,0 @@
1
- const path = require('path');
2
- const { prettierignore, eslintignore } = require('../../config/defaultPaths');
3
- const prettier = path.resolve(__dirname, '../../node_modules/.bin/prettier');
4
- const eslint = path.resolve(__dirname, '../../node_modules/.bin/eslint');
5
- const prettierConfPath = path.resolve(__dirname, './getPrettierConf.js');
6
- const eslintConfPath = path.resolve(__dirname, './getEslintConf.js');
7
-
8
- const prettierCmd = `${prettier} --config ${prettierConfPath} --ignore-path ${prettierignore} --write .`;
9
- const eslintCmd = `${eslint} . -c ${eslintConfPath} --ignore-path ${eslintignore} --ext .js,.jsx,.ts,.tsx --fix`;
10
-
11
- module.exports = {
12
- prettierCmd,
13
- eslintCmd,
14
- };
@@ -1,77 +0,0 @@
1
- const { mergeWithCustomize, unique } = require('webpack-merge');
2
- const { appDirectory, appDist, appTsConfig } = require('../defaultPaths');
3
- const { getFileRealPath } = require('../../util/file');
4
- const { webpack } = require('../../util/userConfig');
5
- const { PROD, DEV } = require('../../constants/env');
6
-
7
- const pluginsUnique = (pluginsName) =>
8
- unique(
9
- 'plugins',
10
- pluginsName,
11
- (plugin) => plugin.constructor && plugin.constructor.name
12
- );
13
-
14
- function getWebpackBaseConf() {
15
- const { opts } = require('../../util/program');
16
- const getLoaders = require('./loaders');
17
- const getPlugins = require('./plugins');
18
- const loaders = getLoaders();
19
- const plugins = getPlugins();
20
- const { hash, ts } = opts;
21
- const entry = {
22
- index: getFileRealPath(`src/index.${ts ? 'tsx' : 'js'}`),
23
- };
24
- const output = {
25
- path: appDist,
26
- filename: hash ? 'js/[name].[contenthash].js' : 'js/[name].js',
27
- publicPath: '/',
28
- };
29
-
30
- const extensions = [
31
- '.js',
32
- '.jsx',
33
- '.ts',
34
- '.tsx',
35
- '.vue',
36
- '.css',
37
- '.scss',
38
- '.less',
39
- '.json',
40
- '.html',
41
- ];
42
-
43
- const webpackConfig = {
44
- mode: process.env.NODE_ENV === PROD ? PROD : DEV,
45
- target: 'web',
46
- context: appDirectory,
47
- entry,
48
- output,
49
- module: {
50
- rules: loaders,
51
- },
52
- plugins,
53
- resolve: {
54
- extensions,
55
- alias: {
56
- vue$: 'vue/dist/vue.esm.js', // TODO: check this with vue framework
57
- },
58
- },
59
- performance: {
60
- hints: false,
61
- },
62
- };
63
- if (ts) {
64
- const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
65
- webpackConfig.resolve.plugins = [
66
- new TsconfigPathsPlugin({
67
- configFile: appTsConfig,
68
- extensions,
69
- }),
70
- ];
71
- }
72
- return mergeWithCustomize({
73
- customizeArray: pluginsUnique(['HtmlWebpackPlugin']),
74
- })(webpackConfig, webpack);
75
- }
76
-
77
- module.exports = getWebpackBaseConf();
@@ -1,39 +0,0 @@
1
- const { merge } = require('webpack-merge');
2
- const { webpack } = require('../../util/userConfig');
3
- const { appDist } = require('../../config/defaultPaths');
4
- const { PORT, HOST } = require('../../constants/default');
5
-
6
- function getDevServerConfig() {
7
- const { opts } = require('../../util/program');
8
- const userDefinedDevServerConfig = webpack.devServer || {};
9
-
10
- const port = opts.port || PORT;
11
- const host = opts.host || HOST;
12
-
13
- const defaultDevServerConfig = {
14
- port,
15
- host,
16
- contentBase: appDist,
17
- historyApiFallback: true,
18
- disableHostCheck: true,
19
- compress: true,
20
- clientLogLevel: 'none',
21
- hot: true,
22
- inline: true,
23
- publicPath: '/',
24
- watchOptions: {
25
- ignored: /node_modules/,
26
- aggregateTimeout: 600,
27
- },
28
- open: true,
29
- headers: {
30
- 'Access-Control-Allow-Origin': '*',
31
- 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
32
- 'Access-Control-Allow-Headers':
33
- 'X-Requested-With, content-type, Authorization',
34
- },
35
- };
36
- return merge(defaultDevServerConfig, userDefinedDevServerConfig);
37
- }
38
-
39
- module.exports = getDevServerConfig;
@@ -1,63 +0,0 @@
1
- const webpack = require('webpack');
2
- const { merge } = require('webpack-merge');
3
- const getDevServerConfig = require('./devServer');
4
-
5
- function getWebpackDev() {
6
- const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
7
- const { opts } = require('../../util/program');
8
- const webpackBaseConf = require('./base');
9
- const plugins = [new webpack.HotModuleReplacementPlugin()];
10
- opts.analyzer && plugins.push(new BundleAnalyzerPlugin());
11
- return merge(webpackBaseConf, {
12
- devtool: 'cheap-module-source-map',
13
- plugins,
14
- });
15
- }
16
-
17
- function getWebpackPro() {
18
- const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
19
- const webpackBaseConf = require('./base');
20
- const willMergeConfig = {
21
- plugins: [],
22
- };
23
- willMergeConfig.optimization = {
24
- moduleIds: 'deterministic',
25
- minimizer: [new CssMinimizerPlugin()],
26
- };
27
- willMergeConfig.plugins.push(
28
- new webpack.optimize.SplitChunksPlugin({
29
- chunks: 'async',
30
- minSize: 30000,
31
- maxSize: 600000,
32
- minChunks: 1,
33
- maxAsyncRequests: 5,
34
- maxInitialRequests: 3,
35
- automaticNameDelimiter: '_',
36
- cacheGroups: {
37
- antd: {
38
- name: 'antd',
39
- test: /[\\/]node_modules[\\/]antd[\\/]/,
40
- chunks: 'initial',
41
- },
42
- lodash: {
43
- name: 'lodash',
44
- test: /[\\/]node_modules[\\/]lodash[\\/]/,
45
- chunks: 'initial',
46
- priority: -10,
47
- },
48
- default: {
49
- minChunks: 2,
50
- priority: -20,
51
- reuseExistingChunk: true,
52
- },
53
- },
54
- })
55
- );
56
- return merge(webpackBaseConf, willMergeConfig);
57
- }
58
-
59
- module.exports = {
60
- getWebpackDev,
61
- getDevServerConfig,
62
- getWebpackPro,
63
- };
@@ -1,142 +0,0 @@
1
- const THREAD_LOADER = require.resolve('thread-loader');
2
- const CSS_LOADER = require.resolve('css-loader');
3
- const LESS_LOADER = require.resolve('less-loader');
4
- const SASS_LOADER = require.resolve('sass-loader');
5
- const POSTCSS_LOADER = require.resolve('postcss-loader');
6
- const BABEL_LOADER = require.resolve('babel-loader');
7
- // const VUE_LOADER = require.resolve('vue-loader'); //TODO: added in the future
8
- const autoprefixer = require('autoprefixer');
9
-
10
- const { babel } = require('../../util/userConfig');
11
- const { PROD } = require('../../constants/env');
12
-
13
- let styleLoader;
14
- if (process.env.NODE_ENV === PROD) {
15
- const MiniCssExtractPluginLoader = require('mini-css-extract-plugin').loader;
16
- styleLoader = {
17
- loader: MiniCssExtractPluginLoader,
18
- };
19
- } else {
20
- const STYLE_LOADER = require.resolve('style-loader');
21
- styleLoader = {
22
- loader: STYLE_LOADER,
23
- };
24
- }
25
-
26
- const postcssLoader = {
27
- loader: POSTCSS_LOADER,
28
- options: {
29
- sourceMap: true,
30
- postcssOptions: {
31
- plugins: [autoprefixer()],
32
- },
33
- },
34
- };
35
-
36
- const babelConf = require('ko-babel-app')(babel.plugins, babel.targets);
37
-
38
- let loaders = [
39
- {
40
- test: /\.css$/,
41
- use: [
42
- styleLoader,
43
- {
44
- loader: CSS_LOADER,
45
- options: {
46
- sourceMap: true,
47
- },
48
- },
49
- postcssLoader,
50
- ],
51
- },
52
- {
53
- test: /\.scss$/,
54
- use: [
55
- styleLoader,
56
- {
57
- loader: CSS_LOADER,
58
- options: {
59
- sourceMap: true,
60
- },
61
- },
62
- postcssLoader,
63
- {
64
- loader: SASS_LOADER,
65
- options: {
66
- sourceMap: true,
67
- },
68
- },
69
- ],
70
- },
71
- {
72
- test: /\.less$/,
73
- use: [
74
- styleLoader,
75
- {
76
- loader: CSS_LOADER,
77
- options: {
78
- sourceMap: true,
79
- },
80
- },
81
- postcssLoader,
82
- {
83
- loader: LESS_LOADER,
84
- options: {
85
- lessOptions: {
86
- javascriptEnabled: true,
87
- },
88
- sourceMap: true,
89
- },
90
- },
91
- ],
92
- },
93
- {
94
- test: /\.jsx?$/,
95
- exclude: /node_modules/,
96
- use: [
97
- THREAD_LOADER,
98
- {
99
- loader: BABEL_LOADER,
100
- options: Object.assign({}, babelConf, {
101
- cacheDirectory: true,
102
- }),
103
- },
104
- ],
105
- },
106
- {
107
- test: /\.(woff|woff2|svg|ttf|eot)$/,
108
- type: 'asset/resource',
109
- generator: {
110
- filename: 'fonts/[hash][ext][query]',
111
- },
112
- },
113
- {
114
- test: /\.(png|jpg|jpeg|gif)$/i,
115
- type: 'asset/resource',
116
- generator: {
117
- filename: 'imgs/[hash][ext][query]',
118
- },
119
- },
120
- ];
121
-
122
- function getLoaders() {
123
- const { opts } = require('../../util/program');
124
- if (opts.ts) {
125
- const TS_LOADER = require.resolve('ts-loader');
126
- const typescriptLoaders = [
127
- {
128
- test: /\.tsx?$/,
129
- exclude: /node_modules/,
130
- loader: TS_LOADER,
131
- options: {
132
- transpileOnly: true,
133
- happyPackMode: true,
134
- },
135
- },
136
- ];
137
- loaders = loaders.concat(typescriptLoaders);
138
- }
139
- return loaders;
140
- }
141
-
142
- module.exports = getLoaders;