@codelet/cli-service 0.0.17 → 0.0.19

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/dist/config.d.ts CHANGED
@@ -6,6 +6,8 @@ export interface Config {
6
6
  source?: string[];
7
7
  /** 不参与打包、运行时 require 的外部脚本 */
8
8
  externalSource?: string[];
9
+ /** 微信构建后的 npm 目录,会原样复制到 dist,并按裸模块外部引入 */
10
+ npmDir?: string;
9
11
  /** 第一页 */
10
12
  pageIndex?: string;
11
13
  /** 静态文件 */
package/dist/config.js CHANGED
@@ -14,11 +14,12 @@ const path_1 = __importDefault(require("path"));
14
14
  const webpackbar_1 = __importDefault(require("webpackbar"));
15
15
  const utils_1 = require("./utils");
16
16
  function getDefaultConfig(options) {
17
- const { entryPath, source, externalSource, pageIndex, publicDir, isDev } = Object.assign({
17
+ const { entryPath, source, externalSource, npmDir, pageIndex, publicDir, isDev } = Object.assign({
18
18
  isDev: false,
19
19
  pageIndex: '',
20
20
  publicDir: 'public',
21
21
  externalSource: [],
22
+ npmDir: '',
22
23
  entryPath: './src',
23
24
  source: [
24
25
  'app.(js|ts)',
@@ -31,6 +32,7 @@ function getDefaultConfig(options) {
31
32
  entryPath,
32
33
  externalFiles,
33
34
  });
35
+ const resolveNpmDirRequest = npmDir ? (0, utils_1.createNpmDirRequestResolver)(npmDir) : () => '';
34
36
  // 模式
35
37
  const mode = isDev ? 'development' : 'production';
36
38
  // 插件
@@ -48,8 +50,12 @@ function getDefaultConfig(options) {
48
50
  from: publicDir, // 源目录
49
51
  to: './', // 复制到输出目录(dist)的根路径
50
52
  noErrorOnMissing: true, // 若 public 目录不存在时不报错
53
+ info: {
54
+ minimized: true,
55
+ },
51
56
  },
52
57
  ...(0, utils_1.createExternalCopyPatterns)(entryPath, externalSource),
58
+ ...(0, utils_1.createNpmDirCopyPatterns)(npmDir),
53
59
  ],
54
60
  }),
55
61
  new webpackbar_1.default(),
@@ -83,11 +89,12 @@ function getDefaultConfig(options) {
83
89
  entryPath,
84
90
  source,
85
91
  externalSource,
92
+ npmDir,
86
93
  publicDir,
87
94
  webpack: {
88
95
  mode,
89
96
  devtool: false,
90
- ...(externalSource.length > 0
97
+ ...(externalSource.length > 0 || Boolean(npmDir)
91
98
  ? {
92
99
  externalsType: 'commonjs',
93
100
  externals: [
@@ -96,6 +103,11 @@ function getDefaultConfig(options) {
96
103
  callback();
97
104
  return;
98
105
  }
106
+ const npmRequest = resolveNpmDirRequest(request);
107
+ if (npmRequest) {
108
+ callback(null, `commonjs ${npmRequest}`);
109
+ return;
110
+ }
99
111
  const targetFile = resolveExternalFile(context, request);
100
112
  if (!targetFile) {
101
113
  callback();
@@ -116,6 +128,9 @@ function getDefaultConfig(options) {
116
128
  publicPath: '/',
117
129
  clean: true,
118
130
  },
131
+ watchOptions: {
132
+ ignored: (0, utils_1.createWatchIgnored)([publicDir, npmDir]),
133
+ },
119
134
  resolve: {
120
135
  alias: {
121
136
  '@': (0, utils_1.resolve)(entryPath),
package/dist/utils.d.ts CHANGED
@@ -13,10 +13,13 @@ export declare const parseDir: (entryPath: string, source: string[]) => {
13
13
  };
14
14
  export declare const resolveExternalFiles: (entryPath: string, externalSource: string[]) => string[];
15
15
  export declare const createExternalCopyPatterns: (entryPath: string, externalSource: string[]) => ObjectPattern[];
16
+ export declare const createNpmDirCopyPatterns: (npmDir: string) => ObjectPattern[];
16
17
  export declare const createExternalRequestResolver: (options: {
17
18
  entryPath: string;
18
19
  externalFiles: string[];
19
20
  }) => (context: string, request: string) => string;
21
+ export declare const createNpmDirRequestResolver: (npmDir: string) => (request: string) => string;
22
+ export declare const createWatchIgnored: (dirs: string[]) => NonNullable<NonNullable<Configuration["watchOptions"]>["ignored"]>;
20
23
  export declare class RewriteExternalRequestPlugin {
21
24
  apply(compiler: Compiler): void;
22
25
  }
package/dist/utils.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createOptimization = exports.RewriteExternalRequestPlugin = exports.createExternalRequestResolver = exports.createExternalCopyPatterns = exports.resolveExternalFiles = exports.parseDir = exports.resolveSourceRoot = exports.resolveEntryRoot = exports.resolve = exports.externalRequestPlaceholderPrefix = exports.cmd = void 0;
6
+ exports.createOptimization = exports.RewriteExternalRequestPlugin = exports.createWatchIgnored = exports.createNpmDirRequestResolver = exports.createExternalRequestResolver = exports.createNpmDirCopyPatterns = exports.createExternalCopyPatterns = exports.resolveExternalFiles = exports.parseDir = exports.resolveSourceRoot = exports.resolveEntryRoot = exports.resolve = exports.externalRequestPlaceholderPrefix = exports.cmd = void 0;
7
7
  exports.getOptionValue = getOptionValue;
8
8
  exports.parseArgv = parseArgv;
9
9
  exports.getConfig = getConfig;
@@ -50,9 +50,28 @@ const createExternalCopyPatterns = (entryPath, externalSource) => {
50
50
  from: pattern,
51
51
  to: '[path][name][ext]',
52
52
  noErrorOnMissing: true,
53
+ info: {
54
+ minimized: true,
55
+ },
53
56
  }));
54
57
  };
55
58
  exports.createExternalCopyPatterns = createExternalCopyPatterns;
59
+ const createNpmDirCopyPatterns = (npmDir) => {
60
+ if (!npmDir) {
61
+ return [];
62
+ }
63
+ return [
64
+ {
65
+ from: (0, exports.resolve)(npmDir),
66
+ to: path_1.default.basename(npmDir),
67
+ noErrorOnMissing: true,
68
+ info: {
69
+ minimized: true,
70
+ },
71
+ },
72
+ ];
73
+ };
74
+ exports.createNpmDirCopyPatterns = createNpmDirCopyPatterns;
56
75
  const createExternalRequestResolver = (options) => {
57
76
  const entryRoot = (0, exports.resolveEntryRoot)(options.entryPath);
58
77
  const externalFileSet = new Set(options.externalFiles);
@@ -80,6 +99,31 @@ const createExternalRequestResolver = (options) => {
80
99
  };
81
100
  };
82
101
  exports.createExternalRequestResolver = createExternalRequestResolver;
102
+ const createNpmDirRequestResolver = (npmDir) => {
103
+ const npmRoot = (0, exports.resolve)(npmDir);
104
+ return (request) => {
105
+ if (!request ||
106
+ request.startsWith('.') ||
107
+ request.startsWith('@/') ||
108
+ path_1.default.isAbsolute(request)) {
109
+ return '';
110
+ }
111
+ const requestPath = request.replace(/\\/g, '/');
112
+ const candidates = [
113
+ path_1.default.join(npmRoot, requestPath),
114
+ path_1.default.join(npmRoot, `${requestPath}.js`),
115
+ path_1.default.join(npmRoot, `${requestPath}.json`),
116
+ path_1.default.join(npmRoot, requestPath, 'index.js'),
117
+ path_1.default.join(npmRoot, requestPath, 'index.json'),
118
+ ];
119
+ return candidates.some((candidate) => fs_1.default.existsSync(candidate)) ? request : '';
120
+ };
121
+ };
122
+ exports.createNpmDirRequestResolver = createNpmDirRequestResolver;
123
+ const createWatchIgnored = (dirs) => {
124
+ return dirs.filter(Boolean).map((dir) => (0, exports.resolve)(dir).replace(/\\/g, '/'));
125
+ };
126
+ exports.createWatchIgnored = createWatchIgnored;
83
127
  class RewriteExternalRequestPlugin {
84
128
  apply(compiler) {
85
129
  compiler.hooks.thisCompilation.tap('RewriteExternalRequestPlugin', (compilation) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codelet/cli-service",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "cli-service",
5
5
  "bin": {
6
6
  "codelet-cli-service": "./bin/codelet-cli-service.js"
@@ -41,10 +41,10 @@
41
41
  "webpack": "5.89.0",
42
42
  "webpack-merge": "^5.10.0",
43
43
  "webpackbar": "^6.0.0",
44
- "@codelet/copy-loader": "^0.0.7",
45
- "@codelet/app-json-webpack-plugin": "^0.0.8",
46
44
  "@codelet/hmr-webpack-plugin": "^0.0.3",
47
45
  "@codelet/inject-chunk-webpack-plugin": "^0.0.8",
46
+ "@codelet/app-json-webpack-plugin": "^0.0.8",
47
+ "@codelet/copy-loader": "^0.0.7",
48
48
  "@codelet/wxml-loader": "^0.0.9"
49
49
  },
50
50
  "devDependencies": {