@shuvi/toolpack 0.0.1-rc.9 → 1.0.0-rc.10

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 (103) hide show
  1. package/lib/babel/plugins/auto-css-modules.js +1 -1
  2. package/lib/babel/plugins/{loadable-plugin.d.ts → dynamic-plugin.d.ts} +1 -1
  3. package/lib/babel/plugins/{loadable-plugin.js → dynamic-plugin.js} +9 -9
  4. package/lib/babel/plugins/optimize-hook-destructuring.d.ts +1 -1
  5. package/lib/babel/plugins/optimize-hook-destructuring.js +4 -4
  6. package/lib/babel/preset.js +25 -5
  7. package/lib/constants.d.ts +1 -0
  8. package/lib/constants.js +5 -1
  9. package/lib/utils/bundle-require.d.ts +33 -0
  10. package/lib/utils/bundle-require.js +143 -0
  11. package/lib/utils/forkTsCheckerWebpackPlugin.js +2 -1
  12. package/lib/utils/formatWebpackMessages.d.ts +18 -4
  13. package/lib/utils/formatWebpackMessages.js +17 -14
  14. package/lib/webpack/config/base.d.ts +17 -4
  15. package/lib/webpack/config/base.js +144 -99
  16. package/lib/webpack/config/browser.d.ts +3 -4
  17. package/lib/webpack/config/browser.js +132 -56
  18. package/lib/webpack/config/index.js +18 -7
  19. package/lib/webpack/config/node.d.ts +3 -4
  20. package/lib/webpack/config/node.js +21 -28
  21. package/lib/webpack/config/parts/external.d.ts +3 -2
  22. package/lib/webpack/config/parts/external.js +16 -10
  23. package/lib/webpack/config/parts/helpers.d.ts +3 -1
  24. package/lib/webpack/config/parts/helpers.js +14 -1
  25. package/lib/webpack/config/parts/resolve.js +1 -0
  26. package/lib/webpack/config/parts/style.d.ts +5 -2
  27. package/lib/webpack/config/parts/style.js +125 -60
  28. package/lib/webpack/dynamic-dll/bundler/index.d.ts +22 -0
  29. package/lib/webpack/dynamic-dll/bundler/index.js +211 -0
  30. package/lib/webpack/dynamic-dll/bundler/webpack-config.d.ts +16 -0
  31. package/lib/webpack/dynamic-dll/bundler/webpack-config.js +116 -0
  32. package/lib/webpack/dynamic-dll/constants.d.ts +6 -0
  33. package/lib/webpack/dynamic-dll/constants.js +9 -0
  34. package/lib/webpack/dynamic-dll/dep/getCJSExports.d.ts +3 -0
  35. package/lib/webpack/dynamic-dll/dep/getCJSExports.js +58 -0
  36. package/lib/webpack/dynamic-dll/dep/getExposeFromContent.d.ts +1 -0
  37. package/lib/webpack/dynamic-dll/dep/getExposeFromContent.js +80 -0
  38. package/lib/webpack/dynamic-dll/dep/getModuleExports.d.ts +7 -0
  39. package/lib/webpack/dynamic-dll/dep/getModuleExports.js +46 -0
  40. package/lib/webpack/dynamic-dll/dep/index.d.ts +13 -0
  41. package/lib/webpack/dynamic-dll/dep/index.js +43 -0
  42. package/lib/webpack/dynamic-dll/helper/check-not-in-node-modules.d.ts +1 -0
  43. package/lib/webpack/dynamic-dll/helper/check-not-in-node-modules.js +15 -0
  44. package/lib/webpack/dynamic-dll/index.d.ts +35 -0
  45. package/lib/webpack/dynamic-dll/index.js +198 -0
  46. package/lib/webpack/dynamic-dll/metadata.d.ts +13 -0
  47. package/lib/webpack/dynamic-dll/metadata.js +62 -0
  48. package/lib/webpack/dynamic-dll/moduleCollector.d.ts +28 -0
  49. package/lib/webpack/dynamic-dll/moduleCollector.js +64 -0
  50. package/lib/webpack/dynamic-dll/plugin/dynamic-dll-plugin.d.ts +24 -0
  51. package/lib/webpack/dynamic-dll/plugin/dynamic-dll-plugin.js +70 -0
  52. package/lib/webpack/dynamic-dll/utils.d.ts +6 -0
  53. package/lib/webpack/dynamic-dll/utils.js +29 -0
  54. package/lib/webpack/index.d.ts +15 -0
  55. package/lib/webpack/index.js +110 -0
  56. package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.d.ts +11 -0
  57. package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.js +40 -0
  58. package/lib/webpack/loaders/parcel-css-loader/index.d.ts +4 -0
  59. package/lib/webpack/loaders/parcel-css-loader/index.js +369 -0
  60. package/lib/webpack/loaders/parcel-css-loader/runtime/api.d.ts +2 -0
  61. package/lib/webpack/loaders/parcel-css-loader/runtime/api.js +85 -0
  62. package/lib/webpack/loaders/parcel-css-loader/runtime/getUrl.d.ts +2 -0
  63. package/lib/webpack/loaders/parcel-css-loader/runtime/getUrl.js +23 -0
  64. package/lib/webpack/loaders/parcel-css-loader/runtime/noSourceMaps.d.ts +2 -0
  65. package/lib/webpack/loaders/parcel-css-loader/runtime/noSourceMaps.js +2 -0
  66. package/lib/webpack/loaders/parcel-css-loader/runtime/sourceMaps.d.ts +2 -0
  67. package/lib/webpack/loaders/parcel-css-loader/runtime/sourceMaps.js +16 -0
  68. package/lib/webpack/loaders/parcel-css-loader/utils.d.ts +28 -0
  69. package/lib/webpack/loaders/parcel-css-loader/utils.js +869 -0
  70. package/lib/webpack/loaders/route-component-loader.js +25 -5
  71. package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.d.ts +94 -0
  72. package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.js +162 -0
  73. package/lib/webpack/loaders/shuvi-swc-loader/index.d.ts +2 -0
  74. package/lib/webpack/loaders/shuvi-swc-loader/index.js +119 -0
  75. package/lib/webpack/plugins/build-manifest-plugin.js +44 -23
  76. package/lib/webpack/plugins/dynamic-public-path-plugin.d.ts +9 -0
  77. package/lib/webpack/plugins/dynamic-public-path-plugin.js +50 -0
  78. package/lib/webpack/plugins/fix-watching-plugin.d.ts +4 -0
  79. package/lib/webpack/plugins/fix-watching-plugin.js +23 -0
  80. package/lib/webpack/plugins/jsconfig-paths-plugin.d.ts +44 -0
  81. package/lib/webpack/plugins/jsconfig-paths-plugin.js +228 -0
  82. package/lib/webpack/plugins/module-replace-plugin/index.js +5 -1
  83. package/lib/webpack/plugins/module-replace-plugin/plugin.d.ts +7 -6
  84. package/lib/webpack/plugins/module-replace-plugin/plugin.js +56 -33
  85. package/lib/webpack/plugins/module-replace-plugin/stub-loader.js +47 -7
  86. package/lib/webpack/plugins/require-cache-hot-reloader-plugin.js +9 -8
  87. package/lib/webpack/plugins/support-ts-extension-resolver-plugin.d.ts +4 -0
  88. package/lib/webpack/plugins/support-ts-extension-resolver-plugin.js +23 -0
  89. package/lib/webpack/types.d.ts +40 -0
  90. package/lib/webpack/types.js +2 -0
  91. package/package.json +46 -40
  92. package/lib/utils/emptyComponent.d.ts +0 -1
  93. package/lib/utils/emptyComponent.js +0 -7
  94. package/lib/utils/errorOverlayMiddleware.d.ts +0 -1
  95. package/lib/utils/errorOverlayMiddleware.js +0 -21
  96. package/lib/utils/hotDevClient/eventsource.d.ts +0 -1
  97. package/lib/utils/hotDevClient/eventsource.js +0 -63
  98. package/lib/utils/hotDevClient/index.d.ts +0 -4
  99. package/lib/utils/hotDevClient/index.js +0 -289
  100. package/lib/utils/verifyTypeScriptSetup.d.ts +0 -5
  101. package/lib/utils/verifyTypeScriptSetup.js +0 -229
  102. package/lib/webpack/loaders/export-global-loader.d.ts +0 -7
  103. package/lib/webpack/loaders/export-global-loader.js +0 -26
@@ -1,55 +1,48 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
- const detectTypescript_1 = require("@shuvi/utils/lib/detectTypescript");
3
+ exports.createNodeWebpackChain = void 0;
15
4
  const base_1 = require("./base");
16
5
  const external_1 = require("./parts/external");
17
6
  const style_1 = require("./parts/style");
18
- const resolve_1 = require("./parts/resolve");
19
- function createNodeWebpackChain(_a) {
20
- var { webpackHelpers } = _a, baseOptions = __rest(_a, ["webpackHelpers"]);
21
- const chain = base_1.baseWebpackChain(baseOptions);
22
- const { useTypeScript } = detectTypescript_1.getTypeScriptInfo(baseOptions.projectRoot);
7
+ function createNodeWebpackChain(options) {
8
+ const { webpackHelpers, typescript, dev } = options;
9
+ const chain = (0, base_1.baseWebpackChain)(options);
10
+ const useTypeScript = !!(typescript === null || typescript === void 0 ? void 0 : typescript.useTypeScript);
23
11
  chain.target('node');
24
- chain.devtool(false);
25
- const extensions = [
26
- ...(useTypeScript ? ['.tsx', '.ts'] : []),
12
+ chain.devtool(dev ? 'cheap-module-source-map' : false);
13
+ chain.resolve.extensions.merge([
14
+ ...(useTypeScript ? ['.ts', '.tsx'] : []),
27
15
  '.js',
28
16
  '.mjs',
29
17
  '.jsx',
30
18
  '.json',
31
19
  '.wasm'
32
- ];
33
- chain.resolve.extensions.merge(baseOptions.target
34
- ? resolve_1.resolvePreferTarget(baseOptions.target, extensions)
35
- : extensions);
20
+ ]);
36
21
  // fix: Can't reexport the named export 'BREAK' from non EcmaScript module
37
22
  // related issue: https://github.com/graphql/graphql-js/issues/1272
38
23
  chain.resolve.mainFields.clear().add('main').add('module');
39
24
  chain.output.libraryTarget('commonjs2');
40
25
  chain.optimization.minimize(false);
41
- webpackHelpers.addExternals(chain, external_1.nodeExternals({ projectRoot: baseOptions.projectRoot }));
26
+ webpackHelpers.addExternals(chain, (0, external_1.nodeExternals)({
27
+ projectRoot: options.projectRoot,
28
+ include: options.include
29
+ }));
42
30
  chain.module
43
31
  .rule('main')
44
32
  .oneOf('js')
45
- .use('shuvi-babel-loader')
46
- .tap(options => (Object.assign(Object.assign({}, options), { isNode: true })));
33
+ .use('shuvi-swc-loader')
34
+ .tap(options => (Object.assign(Object.assign({}, options), { isServer: true })));
47
35
  chain.plugin('private/build-manifest').tap(([options]) => [
48
36
  Object.assign(Object.assign({}, options), { modules: false })
49
37
  ]);
50
38
  chain.plugin('define').tap(([options]) => [
51
39
  Object.assign(Object.assign({}, options), { __BROWSER__: false })
52
40
  ]);
53
- return style_1.withStyle(chain, { ssr: true });
41
+ return (0, style_1.withStyle)(chain, {
42
+ ssr: true,
43
+ parcelCss: options.parcelCss,
44
+ filename: 'static/css/[contenthash:8].css',
45
+ chunkFilename: 'static/css/[contenthash:8].chunk.css'
46
+ });
54
47
  }
55
48
  exports.createNodeWebpackChain = createNodeWebpackChain;
@@ -1,4 +1,5 @@
1
- import { ExternalsFunction } from '@shuvi/types/src/bundler';
2
- export declare function nodeExternals({ projectRoot }: {
1
+ import { ExternalsFunction } from '../../types';
2
+ export declare function nodeExternals({ projectRoot, include }: {
3
+ include: string[];
3
4
  projectRoot: string;
4
5
  }): ExternalsFunction;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nodeExternals = void 0;
3
4
  // import resolve from "resolve";
4
5
  const constants_1 = require("../../../constants");
5
6
  function match(value, tests) {
@@ -21,7 +22,7 @@ function match(value, tests) {
21
22
  }
22
23
  return matched;
23
24
  }
24
- function nodeExternals({ projectRoot }) {
25
+ function nodeExternals({ projectRoot, include }) {
25
26
  const nodeExternal = ({ context, request }, next) => {
26
27
  function transpiled() {
27
28
  return next(null, undefined);
@@ -30,9 +31,14 @@ function nodeExternals({ projectRoot }) {
30
31
  return next(null, `commonjs ${request}`);
31
32
  }
32
33
  const notExternalModules = [];
33
- const externalModules = [/shuvi[/\\]lib[/\\]lib[/\\]runtimeConfig/];
34
+ const externalModules = [
35
+ /platform-shared[/\\](esm|lib)[/\\]shared[/\\]shuvi-singleton-runtimeConfig/
36
+ ];
34
37
  // make sure we don't externalize anything that is
35
38
  // supposed to be transpiled
39
+ if (match(request, include)) {
40
+ return transpiled();
41
+ }
36
42
  if (match(request, constants_1.AppSourceRegexs)) {
37
43
  return transpiled();
38
44
  }
@@ -42,15 +48,15 @@ function nodeExternals({ projectRoot }) {
42
48
  if (match(request, externalModules)) {
43
49
  return external();
44
50
  }
51
+ // Relative requires don't need custom resolution, because they
52
+ // are relative to requests we've already resolved here.
53
+ // Absolute requires (require('/foo')) are extremely uncommon, but
54
+ // also have no need for customization as they're already resolved.
55
+ const start = request.charAt(0);
56
+ if (start === '.' || request.startsWith('/')) {
57
+ return transpiled();
58
+ }
45
59
  next(null, 'next');
46
- // // Relative requires don't need custom resolution, because they
47
- // // are relative to requests we've already resolved here.
48
- // // Absolute requires (require('/foo')) are extremely uncommon, but
49
- // // also have no need for customization as they're already resolved.
50
- // const start = request.charAt(0);
51
- // if (start === "." || request.startsWith("/")) {
52
- // return transpiled();
53
- // }
54
60
  // let res;
55
61
  // try {
56
62
  // res = resolve.sync(request, { basedir: context });
@@ -1,2 +1,4 @@
1
- import { IWebpackHelpers } from '@shuvi/types/src/bundler';
1
+ import { IWebpackHelpers } from '../../types';
2
2
  export declare const webpackHelpers: () => IWebpackHelpers;
3
+ export declare function shouldUseRelativeAssetPaths(publicPath: string): boolean;
4
+ export declare function splitChunksFilter(chunk: any): boolean;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.webpackHelpers = () => {
3
+ exports.splitChunksFilter = exports.shouldUseRelativeAssetPaths = exports.webpackHelpers = void 0;
4
+ const webpackHelpers = () => {
4
5
  const externalFns = [];
5
6
  const defaultExternalsFn = ({ context, request }, callback) => {
6
7
  let callbackCalled = false;
@@ -42,3 +43,15 @@ exports.webpackHelpers = () => {
42
43
  }
43
44
  };
44
45
  };
46
+ exports.webpackHelpers = webpackHelpers;
47
+ function shouldUseRelativeAssetPaths(publicPath) {
48
+ return publicPath === './';
49
+ }
50
+ exports.shouldUseRelativeAssetPaths = shouldUseRelativeAssetPaths;
51
+ function splitChunksFilter(chunk) {
52
+ const excludes = {
53
+ 'static/polyfill': true
54
+ };
55
+ return excludes[chunk.name] !== true;
56
+ }
57
+ exports.splitChunksFilter = splitChunksFilter;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolvePreferTarget = void 0;
3
4
  function resolvePreferTarget(target, extensions) {
4
5
  return extensions.reduce((res, ext) => {
5
6
  res.push(`.${target}${ext}`);
@@ -1,9 +1,12 @@
1
- import Config from 'webpack-chain';
1
+ import { WebpackChain as Config } from '../base';
2
2
  interface StyleOptions {
3
+ filename: string;
4
+ chunkFilename: string;
3
5
  publicPath?: string;
4
6
  extractCss?: boolean;
5
7
  sourceMap?: boolean;
6
8
  ssr?: boolean;
9
+ parcelCss?: boolean;
7
10
  }
8
- export declare function withStyle(chain: Config, { extractCss, sourceMap, ssr, publicPath }: StyleOptions): Config;
11
+ export declare function withStyle(chain: Config, { extractCss, sourceMap, ssr, publicPath, parcelCss, filename, chunkFilename }: StyleOptions): Config;
9
12
  export {};
@@ -1,27 +1,49 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.withStyle = void 0;
6
30
  const constants_1 = require("@shuvi/shared/lib/constants");
7
31
  const Rule_1 = __importDefault(require("webpack-chain/src/Rule"));
8
32
  const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
9
- const loader_utils_1 = __importDefault(require("loader-utils"));
10
- const path_1 = __importDefault(require("path"));
11
- function shouldUseRelativeAssetPaths(publicPath) {
12
- return publicPath === './';
13
- }
33
+ const loaderUtils = __importStar(require("loader-utils"));
34
+ const path = __importStar(require("path"));
35
+ const helpers_1 = require("./helpers");
14
36
  function getCSSModuleLocalIdent(context, localIdentName, localName, options) {
15
37
  // Use the filename or folder name, based on some uses the index.js / index.module.(css|scss|sass) project style
16
38
  const fileNameOrFolder = context.resourcePath.match(/index\.module\.(css|scss|sass)$/)
17
39
  ? '[folder]'
18
40
  : '[name]';
19
41
  // Create a hash based on a the file location and class name. Will be unique across a project, and close to globally unique.
20
- const hash = loader_utils_1.default.getHashDigest(
42
+ const hash = loaderUtils.getHashDigest(
21
43
  // @ts-ignore
22
- path_1.default.posix.relative(context.rootContext, context.resourcePath) + localName, 'md5', 'base64', 5);
44
+ path.posix.relative(context.rootContext, context.resourcePath) + localName, 'md5', 'base64', 5);
23
45
  // Use loaderUtils to find the file or folder name
24
- const className = loader_utils_1.default.interpolateName(context, fileNameOrFolder + '_' + localName + '__' + hash, options);
46
+ const className = loaderUtils.interpolateName(context, fileNameOrFolder + '_' + localName + '__' + hash, options);
25
47
  // remove the .module that appears in every classname when based on the file.
26
48
  return className.replace('.module_', '_');
27
49
  }
@@ -29,32 +51,53 @@ function getCSSModuleLocalIdent(context, localIdentName, localName, options) {
29
51
  const cssRegex = /\.css$/;
30
52
  const cssModuleQueryRegex = /cssmodules/;
31
53
  const sassRegex = /\.(scss|sass)$/;
32
- function ssrCssRule({ test, resourceQuery, scss }) {
54
+ function ssrCssRule({ test, resourceQuery, scss, parcelCss }) {
33
55
  const rule = new Rule_1.default();
34
56
  rule.test(test);
35
57
  if (resourceQuery) {
36
58
  rule.resourceQuery(resourceQuery);
37
59
  }
38
- rule
39
- .use('css-loader')
40
- .loader(require.resolve('css-loader'))
41
- .options({
42
- sourceMap: false,
43
- importLoaders: scss ? 1 : 0,
44
- esModule: true,
45
- modules: {
46
- getLocalIdent: getCSSModuleLocalIdent,
47
- exportOnlyLocals: true
48
- }
49
- });
60
+ if (parcelCss) {
61
+ rule
62
+ .use('parcel-css-loader')
63
+ .loader('@shuvi/parcel-css-loader')
64
+ .options({
65
+ sourceMap: false,
66
+ importLoaders: scss ? 1 : 0,
67
+ esModule: true,
68
+ modules: {
69
+ exportOnlyLocals: true
70
+ }
71
+ });
72
+ }
73
+ else {
74
+ rule
75
+ .use('css-loader')
76
+ .loader(require.resolve('css-loader'))
77
+ .options({
78
+ sourceMap: false,
79
+ importLoaders: scss ? 1 : 0,
80
+ esModule: true,
81
+ modules: {
82
+ getLocalIdent: getCSSModuleLocalIdent,
83
+ exportOnlyLocals: true
84
+ }
85
+ });
86
+ }
50
87
  if (scss) {
51
- rule.use('sass-loader').loader(require.resolve('sass-loader')).options({
52
- sourceMap: false
88
+ rule
89
+ .use('sass-loader')
90
+ .loader(require.resolve('sass-loader'))
91
+ .options({
92
+ sourceMap: false,
93
+ sassOptions: {
94
+ outputStyle: 'expanded'
95
+ }
53
96
  });
54
97
  }
55
98
  return rule;
56
99
  }
57
- function cssRule({ publicPath, test, resourceQuery, cssModule, extractCss, sourceMap, scss }) {
100
+ function cssRule({ publicPath, test, resourceQuery, cssModule, parcelCss, extractCss, sourceMap, scss }) {
58
101
  const rule = new Rule_1.default();
59
102
  rule.test(test);
60
103
  if (resourceQuery) {
@@ -69,7 +112,7 @@ function cssRule({ publicPath, test, resourceQuery, cssModule, extractCss, sourc
69
112
  rule
70
113
  .use('extract-loader')
71
114
  .loader(mini_css_extract_plugin_1.default.loader)
72
- .options(Object.assign({}, (publicPath && shouldUseRelativeAssetPaths(publicPath)
115
+ .options(Object.assign({}, (publicPath && (0, helpers_1.shouldUseRelativeAssetPaths)(publicPath)
73
116
  ? {
74
117
  // path relative to outdir from the generated css file
75
118
  publicPath: '../../'
@@ -101,42 +144,58 @@ function cssRule({ publicPath, test, resourceQuery, cssModule, extractCss, sourc
101
144
  esModule: true
102
145
  });
103
146
  }
104
- rule
105
- .use('css-loader')
106
- .loader(require.resolve('css-loader'))
107
- .options(Object.assign({ sourceMap, importLoaders: scss ? 2 : 1, esModule: true }, (cssModule && {
108
- modules: {
109
- getLocalIdent: getCSSModuleLocalIdent
110
- // exportOnlyLocals: true,
111
- }
112
- })));
113
- rule
114
- .use('postcss-loader')
115
- .loader(require.resolve('postcss-loader'))
116
- .options({
117
- sourceMap,
118
- postcssOptions: {
119
- plugins: [
120
- // Make Flexbox behave like the spec cross-browser.
121
- require('postcss-flexbugs-fixes'),
122
- // Run Autoprefixer and compile new CSS features.
123
- require('postcss-preset-env')({
124
- autoprefixer: {
125
- flexbox: 'no-2009'
126
- },
127
- stage: 3
128
- })
129
- ]
130
- }
131
- });
147
+ if (parcelCss) {
148
+ rule
149
+ .use('parcel-css-loader')
150
+ .loader('@shuvi/parcel-css-loader')
151
+ .options(Object.assign({ sourceMap, importLoaders: scss ? 2 : 1, esModule: true }, (cssModule && {
152
+ modules: {}
153
+ })));
154
+ }
155
+ else {
156
+ rule
157
+ .use('css-loader')
158
+ .loader(require.resolve('css-loader'))
159
+ .options(Object.assign({ sourceMap, importLoaders: scss ? 2 : 1, esModule: true }, (cssModule && {
160
+ modules: {
161
+ getLocalIdent: getCSSModuleLocalIdent
162
+ // exportOnlyLocals: true,
163
+ }
164
+ })));
165
+ rule
166
+ .use('postcss-loader')
167
+ .loader(require.resolve('postcss-loader'))
168
+ .options({
169
+ sourceMap,
170
+ postcssOptions: {
171
+ plugins: [
172
+ // Make Flexbox behave like the spec cross-browser.
173
+ require('postcss-flexbugs-fixes'),
174
+ // Run Autoprefixer and compile new CSS features.
175
+ require('postcss-preset-env')({
176
+ autoprefixer: {
177
+ flexbox: 'no-2009'
178
+ },
179
+ stage: 3
180
+ })
181
+ ]
182
+ }
183
+ });
184
+ }
132
185
  if (scss) {
133
- rule.use('sass-loader').loader(require.resolve('sass-loader')).options({
134
- sourceMap
186
+ rule
187
+ .use('sass-loader')
188
+ .loader(require.resolve('sass-loader'))
189
+ .options({
190
+ sourceMap,
191
+ sassOptions: {
192
+ outputStyle: 'expanded'
193
+ }
135
194
  });
136
195
  }
137
196
  return rule;
138
197
  }
139
- function withStyle(chain, { extractCss, sourceMap, ssr, publicPath }) {
198
+ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath, parcelCss, filename, chunkFilename }) {
140
199
  const oneOfs = chain.module.rule('main').oneOfs;
141
200
  if (ssr) {
142
201
  oneOfs.set('css-module',
@@ -144,14 +203,16 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath }) {
144
203
  ssrCssRule({
145
204
  test: cssRegex,
146
205
  resourceQuery: cssModuleQueryRegex,
147
- scss: false
206
+ scss: false,
207
+ parcelCss
148
208
  }).after('js'));
149
209
  oneOfs.set('scss-module',
150
210
  // @ts-ignore
151
211
  ssrCssRule({
152
212
  test: sassRegex,
153
213
  resourceQuery: cssModuleQueryRegex,
154
- scss: true
214
+ scss: true,
215
+ parcelCss
155
216
  }).after('css-module'));
156
217
  const ignoreRule = new Rule_1.default();
157
218
  ignoreRule
@@ -167,8 +228,8 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath }) {
167
228
  if (extractCss) {
168
229
  chain.plugin('mini-css-extract-plugin').use(mini_css_extract_plugin_1.default, [
169
230
  {
170
- filename: 'static/css/[contenthash:8].css',
171
- chunkFilename: 'static/css/[contenthash:8].chunk.css'
231
+ filename,
232
+ chunkFilename
172
233
  }
173
234
  ]);
174
235
  }
@@ -178,6 +239,7 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath }) {
178
239
  test: cssRegex,
179
240
  resourceQuery: cssModuleQueryRegex,
180
241
  cssModule: true,
242
+ parcelCss,
181
243
  scss: false,
182
244
  extractCss,
183
245
  sourceMap,
@@ -188,6 +250,7 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath }) {
188
250
  cssRule({
189
251
  test: cssRegex,
190
252
  cssModule: false,
253
+ parcelCss,
191
254
  scss: false,
192
255
  extractCss,
193
256
  sourceMap,
@@ -199,6 +262,7 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath }) {
199
262
  test: sassRegex,
200
263
  resourceQuery: cssModuleQueryRegex,
201
264
  cssModule: true,
265
+ parcelCss,
202
266
  scss: true,
203
267
  extractCss,
204
268
  sourceMap,
@@ -209,6 +273,7 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath }) {
209
273
  cssRule({
210
274
  test: sassRegex,
211
275
  cssModule: false,
276
+ parcelCss,
212
277
  scss: true,
213
278
  extractCss,
214
279
  sourceMap,
@@ -0,0 +1,22 @@
1
+ import { Configuration } from 'webpack';
2
+ import WebpackChain from 'webpack-chain';
3
+ import { ModuleSnapshot } from '../moduleCollector';
4
+ export interface BuildOptions {
5
+ outputDir: string;
6
+ configWebpack?: (chain: WebpackChain) => WebpackChain;
7
+ shared?: ShareConfig;
8
+ externals?: Configuration['externals'];
9
+ esmFullSpecific?: Boolean;
10
+ force?: boolean;
11
+ }
12
+ export declare type ShareConfig = Record<string, any>;
13
+ declare type OnBuildComplete = (error?: null | Error) => void;
14
+ export declare class Bundler {
15
+ private _nextBuild;
16
+ private _completeFns;
17
+ private _isBuilding;
18
+ build(snapshot: ModuleSnapshot, options: BuildOptions): Promise<void>;
19
+ private _buildDll;
20
+ onBuildComplete(fn: OnBuildComplete): void;
21
+ }
22
+ export {};