@shuvi/toolpack 1.0.0-rc.16 → 1.0.0-rc.18

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 (26) hide show
  1. package/lib/utils/bundleRequire.js +1 -1
  2. package/lib/webpack/config/base.d.ts +3 -3
  3. package/lib/webpack/config/base.js +5 -6
  4. package/lib/webpack/config/browser.js +1 -1
  5. package/lib/webpack/config/node.js +1 -1
  6. package/lib/webpack/config/parts/external.d.ts +1 -1
  7. package/lib/webpack/config/parts/external.js +1 -8
  8. package/lib/webpack/config/parts/style.d.ts +2 -2
  9. package/lib/webpack/config/parts/style.js +42 -29
  10. package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/CssSyntaxError.d.ts +0 -0
  11. package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/CssSyntaxError.js +0 -0
  12. package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/index.d.ts +0 -0
  13. package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/index.js +47 -47
  14. package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/runtime/api.d.ts +0 -0
  15. package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/runtime/api.js +0 -0
  16. package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/runtime/getUrl.d.ts +0 -0
  17. package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/runtime/getUrl.js +0 -0
  18. package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/runtime/noSourceMaps.d.ts +0 -0
  19. package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/runtime/noSourceMaps.js +0 -0
  20. package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/runtime/sourceMaps.d.ts +0 -0
  21. package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/runtime/sourceMaps.js +0 -0
  22. package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/utils.d.ts +5 -2
  23. package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/utils.js +17 -8
  24. package/package.json +6 -6
  25. package/lib/constants.d.ts +0 -1
  26. package/lib/constants.js +0 -6
@@ -130,7 +130,7 @@ function bundleRequire(filepath, options = {}) {
130
130
  }
131
131
  return mod;
132
132
  });
133
- const result = yield (0, esbuild_1.build)(Object.assign(Object.assign({}, options.esbuildOptions), { entryPoints: [filepath], absWorkingDir: cwd, outfile, format: 'cjs', platform: 'node', sourcemap: 'inline', bundle: true, metafile: true, write: true, watch: false, plugins: [
133
+ const result = yield (0, esbuild_1.build)(Object.assign(Object.assign({}, options.esbuildOptions), { entryPoints: [filepath], absWorkingDir: cwd, outfile, format: 'cjs', target: 'es6', platform: 'node', sourcemap: 'inline', bundle: true, metafile: true, write: true, watch: false, plugins: [
134
134
  ...(((_b = options.esbuildOptions) === null || _b === void 0 ? void 0 : _b.plugins) || []),
135
135
  (0, exports.externalPlugin)({
136
136
  external: options.external
@@ -7,7 +7,7 @@ export interface BaseOptions {
7
7
  projectRoot: string;
8
8
  outputDir: string;
9
9
  cacheDir: string;
10
- include: string[];
10
+ include: (string | RegExp)[];
11
11
  typescript?: {
12
12
  useTypeScript: boolean;
13
13
  typeScriptPath?: string;
@@ -20,8 +20,8 @@ export interface BaseOptions {
20
20
  env?: {
21
21
  [x: string]: string | undefined;
22
22
  };
23
- parcelCss?: boolean;
23
+ lightningCss?: boolean;
24
24
  compiler?: CompilerOptions;
25
25
  }
26
26
  export { WebpackChain };
27
- export declare function baseWebpackChain({ dev, outputDir, parcelCss, compiler, projectRoot, include, typescript, name, publicPath, env, cacheDir }: BaseOptions): WebpackChain;
27
+ export declare function baseWebpackChain({ dev, outputDir, lightningCss, compiler, projectRoot, include, typescript, name, publicPath, env, cacheDir }: BaseOptions): WebpackChain;
@@ -35,7 +35,6 @@ const webpack_1 = __importDefault(require("webpack"));
35
35
  const path = __importStar(require("path"));
36
36
  const constants_1 = require("@shuvi/shared/lib/constants");
37
37
  const fix_watching_plugin_1 = __importDefault(require("../plugins/fix-watching-plugin"));
38
- const constants_2 = require("../../constants");
39
38
  const crypto = __importStar(require("crypto"));
40
39
  const jsconfig_paths_plugin_1 = __importDefault(require("../plugins/jsconfig-paths-plugin"));
41
40
  const support_ts_extension_resolver_plugin_1 = __importDefault(require("../plugins/support-ts-extension-resolver-plugin"));
@@ -60,7 +59,7 @@ const terserOptions = {
60
59
  ascii_only: true
61
60
  }
62
61
  };
63
- function baseWebpackChain({ dev, outputDir, parcelCss, compiler, projectRoot, include, typescript, name, publicPath = '/', env = {}, cacheDir }) {
62
+ function baseWebpackChain({ dev, outputDir, lightningCss, compiler, projectRoot, include, typescript, name, publicPath = '/', env = {}, cacheDir }) {
64
63
  var _a;
65
64
  const config = new webpack_chain_1.default();
66
65
  config.mode(dev ? 'development' : 'production');
@@ -119,8 +118,8 @@ function baseWebpackChain({ dev, outputDir, parcelCss, compiler, projectRoot, in
119
118
  config.optimization.minimizer('cssMinimizer').use(css_minimizer_webpack_plugin_1.default, [
120
119
  {
121
120
  // @ts-ignore
122
- minify: parcelCss
123
- ? css_minimizer_webpack_plugin_1.default.parcelCssMinify
121
+ minify: lightningCss
122
+ ? css_minimizer_webpack_plugin_1.default.lightningCssMinify
124
123
  : css_minimizer_webpack_plugin_1.default.cssnanoMinify
125
124
  }
126
125
  ]);
@@ -138,7 +137,7 @@ function baseWebpackChain({ dev, outputDir, parcelCss, compiler, projectRoot, in
138
137
  config.resolve.alias.set('@swc/helpers', path.dirname(require.resolve(`@swc/helpers/package.json`)));
139
138
  config.resolveLoader.merge({
140
139
  alias: [
141
- 'parcel-css-loader',
140
+ 'lightningcss-loader',
142
141
  'shuvi-swc-loader',
143
142
  'route-component-loader'
144
143
  ].reduce((alias, loader) => {
@@ -157,7 +156,7 @@ function baseWebpackChain({ dev, outputDir, parcelCss, compiler, projectRoot, in
157
156
  mainRule
158
157
  .oneOf('js')
159
158
  .test(/\.(tsx|ts|js|cjs|mjs|jsx)$/)
160
- .include.merge([...include, ...constants_2.AppSourceRegexs])
159
+ .include.merge([...include])
161
160
  .end()
162
161
  .use('shuvi-swc-loader')
163
162
  .loader('@shuvi/shuvi-swc-loader')
@@ -207,7 +207,7 @@ function createBrowserWebpackChain(options) {
207
207
  return (0, style_1.withStyle)(chain, {
208
208
  extractCss: !dev,
209
209
  publicPath,
210
- parcelCss: options.parcelCss,
210
+ lightningCss: options.lightningCss,
211
211
  filename: 'static/css/[contenthash:8].css',
212
212
  chunkFilename: 'static/css/[contenthash:8].chunk.css'
213
213
  });
@@ -37,7 +37,7 @@ function createNodeWebpackChain(options) {
37
37
  ]);
38
38
  return (0, style_1.withStyle)(chain, {
39
39
  ssr: true,
40
- parcelCss: options.parcelCss,
40
+ lightningCss: options.lightningCss,
41
41
  filename: 'static/css/[contenthash:8].css',
42
42
  chunkFilename: 'static/css/[contenthash:8].chunk.css'
43
43
  });
@@ -1,5 +1,5 @@
1
1
  import { ExternalsFunction } from '../../types';
2
2
  export declare function nodeExternals({ projectRoot, include }: {
3
- include: string[];
3
+ include: (string | RegExp)[];
4
4
  projectRoot: string;
5
5
  }): ExternalsFunction;
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nodeExternals = void 0;
4
- // import resolve from "resolve";
5
- const constants_1 = require("../../../constants");
6
4
  function match(value, tests) {
7
5
  let matched = false;
8
6
  for (let index = 0; index < tests.length; index++) {
@@ -31,17 +29,12 @@ function nodeExternals({ projectRoot, include }) {
31
29
  return next(null, `commonjs ${request}`);
32
30
  }
33
31
  const notExternalModules = [];
34
- const externalModules = [
35
- /platform-shared[/\\](esm|lib)[/\\]shared[/\\]shuvi-singleton-runtimeConfig/
36
- ];
32
+ const externalModules = [];
37
33
  // make sure we don't externalize anything that is
38
34
  // supposed to be transpiled
39
35
  if (match(request, include)) {
40
36
  return transpiled();
41
37
  }
42
- if (match(request, constants_1.AppSourceRegexs)) {
43
- return transpiled();
44
- }
45
38
  if (match(request, notExternalModules)) {
46
39
  return transpiled();
47
40
  }
@@ -6,7 +6,7 @@ interface StyleOptions {
6
6
  extractCss?: boolean;
7
7
  sourceMap?: boolean;
8
8
  ssr?: boolean;
9
- parcelCss?: boolean;
9
+ lightningCss?: boolean;
10
10
  }
11
- export declare function withStyle(chain: Config, { extractCss, sourceMap, ssr, publicPath, parcelCss, filename, chunkFilename }: StyleOptions): Config;
11
+ export declare function withStyle(chain: Config, { extractCss, sourceMap, ssr, publicPath, lightningCss, filename, chunkFilename }: StyleOptions): Config;
12
12
  export {};
@@ -33,39 +33,48 @@ const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plug
33
33
  const loaderUtils = __importStar(require("loader-utils"));
34
34
  const path = __importStar(require("path"));
35
35
  const helpers_1 = require("./helpers");
36
- function getCSSModuleLocalIdent(context, localIdentName, localName, options) {
37
- // Use the filename or folder name, based on some uses the index.js / index.module.(css|scss|sass) project style
38
- const fileNameOrFolder = context.resourcePath.match(/index\.module\.(css|scss|sass)$/)
36
+ const regexLikeIndexModule = /(?<!pages[\\/])index\.(scss|sass|css)$/;
37
+ function getCSSModuleLocalIdent(context, _, exportName, options) {
38
+ const relativePath = path
39
+ .relative(context.rootContext, context.resourcePath)
40
+ .replace(/\\+/g, '/');
41
+ // Generate a more meaningful name (parent folder) when the user names the
42
+ // file `index.css`.
43
+ const fileNameOrFolder = regexLikeIndexModule.test(relativePath)
39
44
  ? '[folder]'
40
45
  : '[name]';
41
- // Create a hash based on a the file location and class name. Will be unique across a project, and close to globally unique.
42
- const hash = loaderUtils.getHashDigest(
43
- // @ts-ignore
44
- path.posix.relative(context.rootContext, context.resourcePath) + localName, 'md5', 'base64', 5);
45
- // Use loaderUtils to find the file or folder name
46
- const className = loaderUtils.interpolateName(context, fileNameOrFolder + '_' + localName + '__' + hash, options);
47
- // remove the .module that appears in every classname when based on the file.
48
- return className.replace('.module_', '_');
46
+ // Generate a hash to make the class name unique.
47
+ const hash = loaderUtils.getHashDigest(Buffer.from(`filePath:${relativePath}#className:${exportName}`), 'md5', 'base64', 5);
48
+ // Have webpack interpolate the `[folder]` or `[name]` to its real value.
49
+ return (loaderUtils
50
+ .interpolateName(context, fileNameOrFolder + '_' + exportName + '__' + hash, options)
51
+ // Replace invalid symbols with underscores instead of escaping
52
+ // https://mathiasbynens.be/notes/css-escapes#identifiers-strings
53
+ .replace(/[^a-zA-Z0-9-_]/g, '_')
54
+ // "they cannot start with a digit, two hyphens, or a hyphen followed by a digit [sic]"
55
+ // https://www.w3.org/TR/CSS21/syndata.html#characters
56
+ .replace(/^(\d|--|-\d)/, '__$1'));
49
57
  }
50
58
  // style files regexes
51
59
  const cssRegex = /\.css$/;
52
60
  const cssModuleQueryRegex = /cssmodules/;
53
61
  const sassRegex = /\.(scss|sass)$/;
54
- function ssrCssRule({ test, resourceQuery, scss, parcelCss }) {
62
+ function ssrCssRule({ test, resourceQuery, scss, lightningCss }) {
55
63
  const rule = new Rule_1.default();
56
64
  rule.test(test);
57
65
  if (resourceQuery) {
58
66
  rule.resourceQuery(resourceQuery);
59
67
  }
60
- if (parcelCss) {
68
+ if (lightningCss) {
61
69
  rule
62
- .use('parcel-css-loader')
63
- .loader('@shuvi/parcel-css-loader')
70
+ .use('lightningcss-loader')
71
+ .loader('@shuvi/lightningcss-loader')
64
72
  .options({
65
73
  sourceMap: false,
66
74
  importLoaders: scss ? 1 : 0,
67
75
  esModule: true,
68
76
  modules: {
77
+ getLocalIdent: () => '[name]_[local]__[hash]',
69
78
  exportOnlyLocals: true
70
79
  }
71
80
  });
@@ -97,7 +106,7 @@ function ssrCssRule({ test, resourceQuery, scss, parcelCss }) {
97
106
  }
98
107
  return rule;
99
108
  }
100
- function cssRule({ publicPath, test, resourceQuery, cssModule, parcelCss, extractCss, sourceMap, scss }) {
109
+ function cssRule({ publicPath, test, resourceQuery, cssModule, lightningCss, extractCss, sourceMap, scss }) {
101
110
  const rule = new Rule_1.default();
102
111
  rule.test(test);
103
112
  if (resourceQuery) {
@@ -138,12 +147,15 @@ function cssRule({ publicPath, test, resourceQuery, cssModule, parcelCss, extrac
138
147
  esModule: true
139
148
  });
140
149
  }
141
- if (parcelCss) {
150
+ if (lightningCss) {
142
151
  rule
143
- .use('parcel-css-loader')
144
- .loader('@shuvi/parcel-css-loader')
152
+ .use('lightningcss-loader')
153
+ .loader('@shuvi/lightningcss-loader')
145
154
  .options(Object.assign({ sourceMap, importLoaders: scss ? 2 : 1, esModule: true }, (cssModule && {
146
- modules: {}
155
+ modules: {
156
+ getLocalIdent: () => '[name]_[local]__[hash]',
157
+ exportOnlyLocals: false
158
+ }
147
159
  })));
148
160
  }
149
161
  else {
@@ -152,8 +164,8 @@ function cssRule({ publicPath, test, resourceQuery, cssModule, parcelCss, extrac
152
164
  .loader(require.resolve('css-loader'))
153
165
  .options(Object.assign({ sourceMap, importLoaders: scss ? 2 : 1, esModule: true }, (cssModule && {
154
166
  modules: {
155
- getLocalIdent: getCSSModuleLocalIdent
156
- // exportOnlyLocals: true,
167
+ getLocalIdent: getCSSModuleLocalIdent,
168
+ exportOnlyLocals: false
157
169
  }
158
170
  })));
159
171
  rule
@@ -189,7 +201,7 @@ function cssRule({ publicPath, test, resourceQuery, cssModule, parcelCss, extrac
189
201
  }
190
202
  return rule;
191
203
  }
192
- function withStyle(chain, { extractCss, sourceMap, ssr, publicPath, parcelCss, filename, chunkFilename }) {
204
+ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath, lightningCss, filename, chunkFilename }) {
193
205
  const oneOfs = chain.module.rule('main').oneOfs;
194
206
  if (ssr) {
195
207
  oneOfs.set('css-module',
@@ -198,7 +210,7 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath, parcelCss, f
198
210
  test: cssRegex,
199
211
  resourceQuery: cssModuleQueryRegex,
200
212
  scss: false,
201
- parcelCss
213
+ lightningCss
202
214
  }).after('js'));
203
215
  oneOfs.set('scss-module',
204
216
  // @ts-ignore
@@ -206,8 +218,9 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath, parcelCss, f
206
218
  test: sassRegex,
207
219
  resourceQuery: cssModuleQueryRegex,
208
220
  scss: true,
209
- parcelCss
221
+ lightningCss
210
222
  }).after('css-module'));
223
+ // ignore noraml css module
211
224
  const ignoreRule = new Rule_1.default();
212
225
  ignoreRule
213
226
  .test([cssRegex, sassRegex])
@@ -233,7 +246,7 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath, parcelCss, f
233
246
  test: cssRegex,
234
247
  resourceQuery: cssModuleQueryRegex,
235
248
  cssModule: true,
236
- parcelCss,
249
+ lightningCss,
237
250
  scss: false,
238
251
  extractCss,
239
252
  sourceMap,
@@ -244,7 +257,7 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath, parcelCss, f
244
257
  cssRule({
245
258
  test: cssRegex,
246
259
  cssModule: false,
247
- parcelCss,
260
+ lightningCss,
248
261
  scss: false,
249
262
  extractCss,
250
263
  sourceMap,
@@ -256,7 +269,7 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath, parcelCss, f
256
269
  test: sassRegex,
257
270
  resourceQuery: cssModuleQueryRegex,
258
271
  cssModule: true,
259
- parcelCss,
272
+ lightningCss,
260
273
  scss: true,
261
274
  extractCss,
262
275
  sourceMap,
@@ -267,7 +280,7 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath, parcelCss, f
267
280
  cssRule({
268
281
  test: sassRegex,
269
282
  cssModule: false,
270
- parcelCss,
283
+ lightningCss,
271
284
  scss: true,
272
285
  extractCss,
273
286
  sourceMap,
@@ -38,10 +38,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.raw = void 0;
39
39
  const path = __importStar(require("path"));
40
40
  const browserslist_1 = __importDefault(require("browserslist"));
41
- const css_1 = require("@parcel/css");
41
+ const lightningcss_1 = require("lightningcss");
42
42
  const CssSyntaxError_1 = __importDefault(require("./CssSyntaxError"));
43
43
  const utils_1 = require("./utils");
44
- const browsersTargets = (0, css_1.browserslistToTargets)((0, browserslist_1.default)('last 1 major versions'));
44
+ const browsersTargets = (0, lightningcss_1.browserslistToTargets)((0, browserslist_1.default)('last 1 major versions'));
45
45
  function loader(content, map) {
46
46
  return __awaiter(this, void 0, void 0, function* () {
47
47
  const rawOptions = this.getOptions();
@@ -67,14 +67,14 @@ function loader(content, map) {
67
67
  const isSupportDataURL = options.esModule &&
68
68
  this._compiler &&
69
69
  Boolean('fsStartTime' in this._compiler);
70
- const needToUseIcssPlugin = (0, utils_1.shouldUseIcssPlugin)(options);
71
- let ParcelCssRes;
70
+ const cssModule = (0, utils_1.getCssModuleOptions)(options);
71
+ let LightningCssRes;
72
72
  try {
73
- ParcelCssRes = (0, css_1.transform)({
73
+ LightningCssRes = (0, lightningcss_1.transform)({
74
74
  filename: path.relative(this.rootContext, this.resourcePath),
75
75
  code: content instanceof Buffer ? content : Buffer.from(content),
76
76
  // minify: this.mode === 'production',
77
- cssModules: needToUseIcssPlugin,
77
+ cssModules: cssModule,
78
78
  analyzeDependencies: true,
79
79
  sourceMap: options.sourceMap,
80
80
  drafts: {
@@ -85,7 +85,7 @@ function loader(content, map) {
85
85
  targets: browsersTargets
86
86
  });
87
87
  if (options.sourceMap && map) {
88
- ParcelCssRes.map = (0, utils_1.normalizeSourceMap)(map, this.resourcePath);
88
+ LightningCssRes.map = (0, utils_1.normalizeSourceMap)(map, this.resourcePath);
89
89
  }
90
90
  }
91
91
  catch (error) {
@@ -95,15 +95,15 @@ function loader(content, map) {
95
95
  }
96
96
  return;
97
97
  }
98
- const { dependencies = [] } = ParcelCssRes;
99
- const parcelImportsMap = new Map();
100
- const parcelUrlsMap = new Map();
98
+ const { dependencies = [] } = LightningCssRes;
99
+ const lightningImportsMap = new Map();
100
+ const lightningUrlsMap = new Map();
101
101
  const icssMap = new Map();
102
- const parcelReplacementsMap = new Map();
103
- const parcelImports = [];
104
- const parcelApis = [];
105
- const parcelReplacements = [];
106
- const parcelExports = [];
102
+ const lightningReplacementsMap = new Map();
103
+ const lightningImports = [];
104
+ const lightningApis = [];
105
+ const lightningReplacements = [];
106
+ const lightningExports = [];
107
107
  let hasUrlImportHelper = false;
108
108
  for (let index = 0; index < dependencies.length; index++) {
109
109
  const dep = dependencies[index];
@@ -152,7 +152,7 @@ function loader(content, map) {
152
152
  url = resolvedUrl;
153
153
  }
154
154
  if (!requestable) {
155
- parcelApis.push({
155
+ lightningApis.push({
156
156
  url,
157
157
  layer: undefined,
158
158
  supports,
@@ -162,19 +162,19 @@ function loader(content, map) {
162
162
  continue;
163
163
  }
164
164
  url = prefix ? `${prefix}!${url}` : url;
165
- let importName = parcelImportsMap.get(url);
165
+ let importName = lightningImportsMap.get(url);
166
166
  if (!importName) {
167
- const { size } = parcelImportsMap;
167
+ const { size } = lightningImportsMap;
168
168
  importName = `___CSS_LOADER_AT_RULE_IMPORT_${size}___`;
169
- parcelImportsMap.set(url, importName);
170
- parcelImports.push({
169
+ lightningImportsMap.set(url, importName);
170
+ lightningImports.push({
171
171
  type: 'rule_import',
172
172
  importName,
173
173
  url: (0, utils_1.stringifyRequest)(this, (0, utils_1.combineRequests)((0, utils_1.getPreRequester)(this)(options.importLoaders), url)),
174
174
  index: size
175
175
  });
176
176
  }
177
- parcelApis.push({
177
+ lightningApis.push({
178
178
  importName,
179
179
  layer: undefined,
180
180
  supports,
@@ -191,9 +191,9 @@ function loader(content, map) {
191
191
  // console.log("-> url6 6", url, requestable, needResolve);
192
192
  // Do not traverse inside `url`
193
193
  if (!requestable && !needResolve) {
194
- if (!parcelReplacementsMap.get(url)) {
195
- parcelReplacementsMap.set(url, placeholder);
196
- parcelReplacements.push({
194
+ if (!lightningReplacementsMap.get(url)) {
195
+ lightningReplacementsMap.set(url, placeholder);
196
+ lightningReplacements.push({
197
197
  placeholder,
198
198
  replacementName: url,
199
199
  hash: undefined,
@@ -230,7 +230,7 @@ function loader(content, map) {
230
230
  }
231
231
  }
232
232
  if (!hasUrlImportHelper) {
233
- parcelImports.push({
233
+ lightningImports.push({
234
234
  type: 'get_url_import',
235
235
  importName: '___CSS_LOADER_GET_URL_IMPORT___',
236
236
  url: (0, utils_1.stringifyRequest)(this, require.resolve('./runtime/getUrl.js')),
@@ -239,17 +239,17 @@ function loader(content, map) {
239
239
  hasUrlImportHelper = true;
240
240
  }
241
241
  url = prefix ? `${prefix}!${url}` : url;
242
- let importName = parcelUrlsMap.get(url);
242
+ let importName = lightningUrlsMap.get(url);
243
243
  if (!importName) {
244
- importName = `___CSS_LOADER_URL_IMPORT_${parcelUrlsMap.size}___`;
245
- parcelUrlsMap.set(url, importName);
246
- parcelImports.push({
244
+ importName = `___CSS_LOADER_URL_IMPORT_${lightningUrlsMap.size}___`;
245
+ lightningUrlsMap.set(url, importName);
246
+ lightningImports.push({
247
247
  // type: 'url',
248
248
  importName,
249
249
  url: (0, utils_1.stringifyRequest)(this, url),
250
250
  index
251
251
  });
252
- parcelReplacements.push({
252
+ lightningReplacements.push({
253
253
  placeholder,
254
254
  replacementName: `___CSS_LOADER_URL_REPLACEMENT_${index}___`,
255
255
  importName,
@@ -260,7 +260,7 @@ function loader(content, map) {
260
260
  }
261
261
  }
262
262
  }
263
- if (ParcelCssRes.exports) {
263
+ if (LightningCssRes.exports) {
264
264
  const resolver = this.getResolve({
265
265
  dependencyType: 'icss',
266
266
  conditionNames: ['style'],
@@ -269,9 +269,9 @@ function loader(content, map) {
269
269
  mainFiles: ['index', '...'],
270
270
  preferRelative: true
271
271
  });
272
- const exportKeys = Object.keys(ParcelCssRes.exports);
272
+ const exportKeys = Object.keys(LightningCssRes.exports);
273
273
  for (const exportKey of exportKeys) {
274
- const exportItem = ParcelCssRes.exports[exportKey];
274
+ const exportItem = LightningCssRes.exports[exportKey];
275
275
  const { name, composes } = exportItem;
276
276
  let value = name;
277
277
  for (const compose of composes) {
@@ -301,17 +301,17 @@ function loader(content, map) {
301
301
  const index = icssMap.size;
302
302
  importName = `___CSS_LOADER_ICSS_IMPORT_${index}___`;
303
303
  icssMap.set(url, importName);
304
- parcelImports.push({
304
+ lightningImports.push({
305
305
  type: 'icss_import',
306
306
  importName,
307
307
  url: (0, utils_1.stringifyRequest)(this, (0, utils_1.combineRequests)((0, utils_1.getPreRequester)(this)(options.importLoaders), url)),
308
308
  icss: true,
309
309
  index
310
310
  });
311
- parcelApis.push({ importName, dedupe: true, index });
311
+ lightningApis.push({ importName, dedupe: true, index });
312
312
  }
313
- const replacementName = `___REPLACEMENT_${parcelReplacements.length}_${importName}`;
314
- parcelReplacements.push({
313
+ const replacementName = `___REPLACEMENT_${lightningReplacements.length}_${importName}`;
314
+ lightningReplacements.push({
315
315
  localName: compose.name,
316
316
  replacementName,
317
317
  importName
@@ -319,39 +319,39 @@ function loader(content, map) {
319
319
  value += ` ${replacementName}`;
320
320
  }
321
321
  }
322
- parcelExports.push({
322
+ lightningExports.push({
323
323
  name: exportKey,
324
324
  value
325
325
  });
326
326
  }
327
327
  }
328
328
  if (options.modules.exportOnlyLocals !== true) {
329
- parcelImports.unshift({
329
+ lightningImports.unshift({
330
330
  type: 'api_import',
331
331
  importName: '___CSS_LOADER_API_IMPORT___',
332
332
  url: (0, utils_1.stringifyRequest)(this, require.resolve('./runtime/api'))
333
333
  });
334
334
  if (options.sourceMap) {
335
- parcelImports.unshift({
335
+ lightningImports.unshift({
336
336
  importName: '___CSS_LOADER_API_SOURCEMAP_IMPORT___',
337
337
  url: (0, utils_1.stringifyRequest)(this, require.resolve('./runtime/sourceMaps'))
338
338
  });
339
339
  }
340
340
  else {
341
- parcelImports.unshift({
341
+ lightningImports.unshift({
342
342
  importName: '___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___',
343
343
  url: (0, utils_1.stringifyRequest)(this, require.resolve('./runtime/noSourceMaps'))
344
344
  });
345
345
  }
346
346
  }
347
- parcelImportsMap.clear();
348
- parcelUrlsMap.clear();
347
+ lightningImportsMap.clear();
348
+ lightningUrlsMap.clear();
349
349
  icssMap.clear();
350
- parcelReplacementsMap.clear();
351
- const importCode = (0, utils_1.getImportCode)(parcelImports, options);
350
+ lightningReplacementsMap.clear();
351
+ const importCode = (0, utils_1.getImportCode)(lightningImports, options);
352
352
  let moduleCode;
353
353
  try {
354
- moduleCode = (0, utils_1.getParcelCssModuleCode)(ParcelCssRes, parcelApis, parcelReplacements, options, this);
354
+ moduleCode = (0, utils_1.getLightningCssModuleCode)(LightningCssRes, lightningApis, lightningReplacements, options, this);
355
355
  }
356
356
  catch (error) {
357
357
  if (callback) {
@@ -359,7 +359,7 @@ function loader(content, map) {
359
359
  }
360
360
  return;
361
361
  }
362
- const exportCode = (0, utils_1.getExportCode)(parcelExports, parcelReplacements, needToUseIcssPlugin, options);
362
+ const exportCode = (0, utils_1.getExportCode)(lightningExports, lightningReplacements, cssModule, options);
363
363
  const resultCode = `${importCode}${moduleCode}${exportCode}`;
364
364
  if (callback) {
365
365
  callback(null, resultCode);
@@ -7,7 +7,10 @@ export function normalizeOptions(rawOptions: any, loaderContext: any): {
7
7
  esModule: any;
8
8
  exportType: any;
9
9
  };
10
- export function shouldUseIcssPlugin(options: any): boolean;
10
+ export function getCssModuleOptions(options: any): boolean | {
11
+ pattern: any;
12
+ dashedIdents: boolean;
13
+ };
11
14
  export function normalizeUrl(url: any, isStringValue: any): any;
12
15
  export function requestify(url: any, rootContext: any, needToResolveURL?: boolean): any;
13
16
  export function normalizeSourceMap(map: any, resourcePath: any): any;
@@ -16,7 +19,7 @@ export function getPreRequester({ loaders, loaderIndex }: {
16
19
  loaderIndex: any;
17
20
  }): (number: any) => any;
18
21
  export function getImportCode(imports: any, options: any): string;
19
- export function getParcelCssModuleCode(result: any, api: any, replacements: any, options: any, loaderContext: any): string;
22
+ export function getLightningCssModuleCode(result: any, api: any, replacements: any, options: any, loaderContext: any): string;
20
23
  export function getExportCode(exports: any, replacements: any, icssPluginUsed: any, options: any): string;
21
24
  export function resolveRequests(resolve: any, context: any, possibleRequests: any): Promise<any>;
22
25
  export function isURLRequestable(url: any, options?: {}): {
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.isDataUrl = exports.stringifyRequest = exports.combineRequests = exports.isURLRequestable = exports.resolveRequests = exports.getExportCode = exports.getParcelCssModuleCode = exports.getImportCode = exports.getPreRequester = exports.normalizeSourceMap = exports.requestify = exports.normalizeUrl = exports.shouldUseIcssPlugin = exports.normalizeOptions = void 0;
15
+ exports.isDataUrl = exports.stringifyRequest = exports.combineRequests = exports.isURLRequestable = exports.resolveRequests = exports.getExportCode = exports.getLightningCssModuleCode = exports.getImportCode = exports.getPreRequester = exports.normalizeSourceMap = exports.requestify = exports.normalizeUrl = exports.getCssModuleOptions = exports.normalizeOptions = void 0;
16
16
  /*
17
17
  MIT License http://www.opensource.org/licenses/mit-license.php
18
18
  Author Tobias Koppers @sokra
@@ -535,10 +535,19 @@ function normalizeOptions(rawOptions, loaderContext) {
535
535
  };
536
536
  }
537
537
  exports.normalizeOptions = normalizeOptions;
538
- function shouldUseIcssPlugin(options) {
538
+ function getCssModuleOptions(options) {
539
+ if (typeof options.modules === 'object') {
540
+ const modules = options.modules;
541
+ return {
542
+ pattern: modules.getLocalIdent
543
+ ? modules.getLocalIdent()
544
+ : '[local]_[hash]',
545
+ dashedIdents: Boolean(modules.dashedIdents)
546
+ };
547
+ }
539
548
  return Boolean(options.modules);
540
549
  }
541
- exports.shouldUseIcssPlugin = shouldUseIcssPlugin;
550
+ exports.getCssModuleOptions = getCssModuleOptions;
542
551
  const ABSOLUTE_SCHEME = /^[a-z0-9+\-.]+:/i;
543
552
  function getURLType(source) {
544
553
  if (source[0] === '/') {
@@ -626,7 +635,7 @@ function getImportCode(imports, options) {
626
635
  return code ? `// Imports\n${code}` : '';
627
636
  }
628
637
  exports.getImportCode = getImportCode;
629
- function normalizeParcelCssSourceMapForRuntime(map, loaderContext) {
638
+ function normalizeLightningCssSourceMapForRuntime(map, loaderContext) {
630
639
  let resultMap = null;
631
640
  if (map instanceof Buffer) {
632
641
  resultMap = JSON.parse(map.toString());
@@ -676,14 +685,14 @@ function printParams(media, dedupe, supports, layer) {
676
685
  }
677
686
  return result;
678
687
  }
679
- function getParcelCssModuleCode(result, api, replacements, options, loaderContext) {
688
+ function getLightningCssModuleCode(result, api, replacements, options, loaderContext) {
680
689
  if (options.modules.exportOnlyLocals === true) {
681
690
  return '';
682
691
  }
683
692
  let sourceMapValue = '';
684
693
  if (options.sourceMap) {
685
694
  const sourceMap = result.map;
686
- sourceMapValue = `,${normalizeParcelCssSourceMapForRuntime(sourceMap, loaderContext)}`;
695
+ sourceMapValue = `,${normalizeLightningCssSourceMapForRuntime(sourceMap, loaderContext)}`;
687
696
  }
688
697
  let code = JSON.stringify(result.code.toString());
689
698
  let beforeCode = `var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(${options.sourceMap
@@ -732,13 +741,13 @@ function getParcelCssModuleCode(result, api, replacements, options, loaderContex
732
741
  // 5 - layer
733
742
  return `${beforeCode}// Module\n___CSS_LOADER_EXPORT___.push([module.id, ${code}, ""${sourceMapValue}]);\n`;
734
743
  }
735
- exports.getParcelCssModuleCode = getParcelCssModuleCode;
744
+ exports.getLightningCssModuleCode = getLightningCssModuleCode;
736
745
  function dashesCamelCase(str) {
737
746
  return str.replace(/-+(\w)/g, (match, firstLetter) => firstLetter.toUpperCase());
738
747
  }
739
748
  function getExportCode(exports, replacements, icssPluginUsed, options) {
740
749
  let code = '// Exports\n';
741
- if (icssPluginUsed) {
750
+ if (Boolean(icssPluginUsed)) {
742
751
  let localsCode = '';
743
752
  const addExportToLocalsCode = (names, value) => {
744
753
  const normalizedNames = Array.isArray(names)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/toolpack",
3
- "version": "1.0.0-rc.16",
3
+ "version": "1.0.0-rc.18",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/shuvijs/shuvi.git",
@@ -20,7 +20,7 @@
20
20
  "node": ">= 12.0.0"
21
21
  },
22
22
  "dependencies": {
23
- "@shuvi/compiler": "1.0.0-rc.16",
23
+ "@shuvi/compiler": "1.0.0-rc.18",
24
24
  "@babel/core": "7.12.10",
25
25
  "@babel/plugin-proposal-class-properties": "7.12.1",
26
26
  "@babel/plugin-proposal-nullish-coalescing-operator": "7.10.1",
@@ -34,9 +34,9 @@
34
34
  "@babel/preset-react": "7.10.1",
35
35
  "@babel/preset-typescript": "7.12.7",
36
36
  "@babel/runtime": "7.12.5",
37
- "@parcel/css": "1.2.0",
38
- "@shuvi/shared": "1.0.0-rc.16",
39
- "@shuvi/utils": "1.0.0-rc.16",
37
+ "lightningcss": "1.15.0",
38
+ "@shuvi/shared": "1.0.0-rc.18",
39
+ "@shuvi/utils": "1.0.0-rc.18",
40
40
  "babel-loader": "8.2.2",
41
41
  "babel-plugin-syntax-jsx": "6.18.0",
42
42
  "babel-plugin-transform-define": "2.0.0",
@@ -46,7 +46,7 @@
46
46
  "cross-spawn": "7.0.3",
47
47
  "crypto-browserify": "3.12.0",
48
48
  "css-loader": "5.0.1",
49
- "css-minimizer-webpack-plugin": "3.4.1",
49
+ "css-minimizer-webpack-plugin": "4.1.0",
50
50
  "es-module-lexer": "0.10.5",
51
51
  "esbuild": "0.14.38",
52
52
  "esbuild-loader": "2.19.0",
@@ -1 +0,0 @@
1
- export declare const AppSourceRegexs: RegExp[];
package/lib/constants.js DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AppSourceRegexs = void 0;
4
- exports.AppSourceRegexs = [
5
- /([/\\]shuvi-app[/\\])|([/\\]\.shuvi[/\\])/
6
- ];