@shuvi/toolpack 1.0.0-rc.2 → 1.0.0-rc.5
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/lib/constants.d.ts +0 -1
- package/lib/constants.js +1 -2
- package/lib/utils/formatWebpackMessages.d.ts +18 -4
- package/lib/utils/formatWebpackMessages.js +15 -13
- package/lib/webpack/config/base.d.ts +3 -1
- package/lib/webpack/config/base.js +12 -5
- package/lib/webpack/config/node.js +1 -1
- package/lib/webpack/dynamic-dll/index.d.ts +2 -2
- package/lib/webpack/dynamic-dll/index.js +26 -26
- package/lib/webpack/index.d.ts +3 -3
- package/lib/webpack/index.js +3 -3
- package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.d.ts +9 -2
- package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.js +2 -1
- package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.d.ts +94 -0
- package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.js +162 -0
- package/lib/webpack/loaders/{shuvi-swc-loader.d.ts → shuvi-swc-loader/index.d.ts} +0 -0
- package/lib/webpack/loaders/{shuvi-swc-loader.js → shuvi-swc-loader/index.js} +49 -26
- package/lib/webpack/plugins/module-replace-plugin/plugin.d.ts +1 -0
- package/lib/webpack/plugins/module-replace-plugin/plugin.js +9 -0
- package/package.json +7 -39
- package/lib/swc/tests/fixture/auto-css-module/no-flag/input.d.ts +0 -1
- package/lib/swc/tests/fixture/auto-css-module/no-flag/input.js +0 -4
- package/lib/swc/tests/fixture/auto-css-module/no-flag/output.d.ts +0 -1
- package/lib/swc/tests/fixture/auto-css-module/no-flag/output.js +0 -4
- package/lib/swc/tests/fixture/auto-css-module/with-flag/input.d.ts +0 -1
- package/lib/swc/tests/fixture/auto-css-module/with-flag/input.js +0 -2
- package/lib/swc/tests/fixture/auto-css-module/with-flag/output.d.ts +0 -1
- package/lib/swc/tests/fixture/auto-css-module/with-flag/output.js +0 -2
- package/lib/swc/tests/fixture/shuvi-dynamic/duplicated-imports/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/duplicated-imports/input.js +0 -5
- package/lib/swc/tests/fixture/shuvi-dynamic/duplicated-imports/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/duplicated-imports/output.js +0 -11
- package/lib/swc/tests/fixture/shuvi-dynamic/member-with-same-name/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/member-with-same-name/input.js +0 -9
- package/lib/swc/tests/fixture/shuvi-dynamic/member-with-same-name/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/member-with-same-name/output.js +0 -12
- package/lib/swc/tests/fixture/shuvi-dynamic/no-options/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/no-options/input.js +0 -4
- package/lib/swc/tests/fixture/shuvi-dynamic/no-options/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/no-options/output.js +0 -7
- package/lib/swc/tests/fixture/shuvi-dynamic/with-options/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/with-options/input.js +0 -4
- package/lib/swc/tests/fixture/shuvi-dynamic/with-options/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/with-options/output.js +0 -8
- package/lib/swc/tests/fixture/shuvi-dynamic/wrapped-import/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/wrapped-import/input.js +0 -7
- package/lib/swc/tests/fixture/shuvi-dynamic/wrapped-import/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/wrapped-import/output.js +0 -9
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/duplicated-imports/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/duplicated-imports/input.js +0 -5
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/duplicated-imports/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/duplicated-imports/output.js +0 -11
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/member-with-same-name/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/member-with-same-name/input.js +0 -9
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/member-with-same-name/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/member-with-same-name/output.js +0 -12
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/no-options/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/no-options/input.js +0 -4
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/no-options/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/no-options/output.js +0 -7
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/with-options/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/with-options/input.js +0 -4
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/with-options/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/with-options/output.js +0 -8
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/wrapped-import/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/wrapped-import/input.js +0 -7
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/wrapped-import/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/wrapped-import/output.js +0 -9
- package/lib/swc/tests/full/auto-cjs/1/input.d.ts +0 -1
- package/lib/swc/tests/full/auto-cjs/1/input.js +0 -8
- package/lib/swc/tests/full/auto-cjs/1/output.d.ts +0 -1
- package/lib/swc/tests/full/auto-cjs/1/output.js +0 -8
- package/lib/utils/getSWCOptions.d.ts +0 -91
- package/lib/utils/getSWCOptions.js +0 -66
- package/lib/utils/hotDevClient/eventsource.d.ts +0 -1
- package/lib/utils/hotDevClient/eventsource.js +0 -64
- package/lib/utils/hotDevClient/index.d.ts +0 -4
- package/lib/utils/hotDevClient/index.js +0 -373
- package/lib/utils/hotDevClient/websocket.d.ts +0 -13
- package/lib/utils/hotDevClient/websocket.js +0 -59
- package/lib/utils/load-sources.d.ts +0 -3
- package/lib/utils/load-sources.js +0 -96
package/lib/constants.d.ts
CHANGED
package/lib/constants.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.AppSourceRegexs = void 0;
|
|
4
4
|
exports.AppSourceRegexs = [
|
|
5
5
|
/([/\\]shuvi-app[/\\])|([/\\]\.shuvi[/\\])/
|
|
6
6
|
];
|
|
7
|
-
exports.DEFAULT_TIMEOUT_MS = 5000;
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2015-present, Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
interface StatsError {
|
|
8
|
+
moduleName?: string;
|
|
9
|
+
file?: string;
|
|
10
|
+
message?: string;
|
|
11
|
+
}
|
|
12
|
+
declare function formatWebpackMessages(json: {
|
|
13
|
+
warnings?: StatsError[];
|
|
14
|
+
errors?: StatsError[];
|
|
15
|
+
}): {
|
|
16
|
+
errors: string[];
|
|
17
|
+
warnings: string[];
|
|
5
18
|
};
|
|
19
|
+
export default formatWebpackMessages;
|
|
@@ -1,22 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
3
4
|
*
|
|
4
5
|
* This source code is licensed under the MIT license found in the
|
|
5
6
|
* LICENSE file in the root directory of this source tree.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const
|
|
12
|
+
const chalk_1 = __importDefault(require("@shuvi/utils/lib/chalk"));
|
|
10
13
|
const friendlySyntaxErrorLabel = 'Syntax error:';
|
|
11
14
|
function isLikelyASyntaxError(message) {
|
|
12
15
|
return message.indexOf(friendlySyntaxErrorLabel) !== -1;
|
|
13
16
|
}
|
|
14
17
|
// Cleans up webpack error messages.
|
|
15
|
-
function formatMessage(
|
|
16
|
-
message =
|
|
17
|
-
(
|
|
18
|
-
|
|
19
|
-
message.message;
|
|
18
|
+
function formatMessage(stats, isError) {
|
|
19
|
+
let message = (stats.moduleName ? stats.moduleName + '\n' : '') +
|
|
20
|
+
(stats.file ? stats.file + '\n' : '') +
|
|
21
|
+
stats.message;
|
|
20
22
|
let lines = message.split('\n');
|
|
21
23
|
// Strip Webpack-added headers off errors/warnings
|
|
22
24
|
// https://github.com/webpack/webpack/blob/master/lib/ModuleError.js
|
|
@@ -55,12 +57,12 @@ function formatMessage(message, isError) {
|
|
|
55
57
|
];
|
|
56
58
|
}
|
|
57
59
|
// Add helpful message for users trying to use Sass for the first time
|
|
58
|
-
if (lines[1] && lines[1].match(/Cannot find module.+
|
|
59
|
-
lines[1] = 'To import Sass files, you first need to install
|
|
60
|
+
if (lines[1] && lines[1].match(/Cannot find module.+sass/)) {
|
|
61
|
+
lines[1] = 'To import Sass files, you first need to install sass.\n';
|
|
60
62
|
lines[1] +=
|
|
61
|
-
'Run `npm install
|
|
63
|
+
'Run `npm install sass` or `yarn add sass` inside your workspace.';
|
|
62
64
|
}
|
|
63
|
-
lines[0] =
|
|
65
|
+
lines[0] = chalk_1.default.inverse(lines[0]);
|
|
64
66
|
message = lines.join('\n');
|
|
65
67
|
// Internal stacks are generally useless so we strip them... with the
|
|
66
68
|
// exception of stacks containing `webpack:` because they're normally
|
|
@@ -76,10 +78,10 @@ function formatMessage(message, isError) {
|
|
|
76
78
|
return message.trim();
|
|
77
79
|
}
|
|
78
80
|
function formatWebpackMessages(json) {
|
|
79
|
-
const formattedErrors = json.errors.map(function (message) {
|
|
81
|
+
const formattedErrors = (json.errors || []).map(function (message) {
|
|
80
82
|
return formatMessage(message, true);
|
|
81
83
|
});
|
|
82
|
-
const formattedWarnings = json.warnings.map(function (message) {
|
|
84
|
+
const formattedWarnings = (json.warnings || []).map(function (message) {
|
|
83
85
|
return formatMessage(message, false);
|
|
84
86
|
});
|
|
85
87
|
const result = { errors: formattedErrors, warnings: formattedWarnings };
|
|
@@ -21,6 +21,8 @@ export interface BaseOptions {
|
|
|
21
21
|
env?: {
|
|
22
22
|
[x: string]: string | undefined;
|
|
23
23
|
};
|
|
24
|
+
experimental?: Record<string, any>;
|
|
25
|
+
compiler?: Record<string, any>;
|
|
24
26
|
}
|
|
25
27
|
export { WebpackChain };
|
|
26
|
-
export declare function baseWebpackChain({ dev, outputDir, parcelCss, projectRoot, include, typescript, name, buildManifestFilename, publicPath, env, cacheDir }: BaseOptions): WebpackChain;
|
|
28
|
+
export declare function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, projectRoot, include, typescript, name, buildManifestFilename, publicPath, env, cacheDir }: BaseOptions): WebpackChain;
|
|
@@ -61,7 +61,7 @@ const terserOptions = {
|
|
|
61
61
|
ascii_only: true
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
|
-
function baseWebpackChain({ dev, outputDir, parcelCss, projectRoot, include, typescript, name, buildManifestFilename, publicPath = '/', env = {}, cacheDir }) {
|
|
64
|
+
function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, projectRoot, include, typescript, name, buildManifestFilename, publicPath = '/', env = {}, cacheDir }) {
|
|
65
65
|
var _a;
|
|
66
66
|
const config = new webpack_chain_1.default();
|
|
67
67
|
config.mode(dev ? 'development' : 'production');
|
|
@@ -105,7 +105,9 @@ function baseWebpackChain({ dev, outputDir, parcelCss, projectRoot, include, typ
|
|
|
105
105
|
hotUpdateMainFilename: 'static/webpack/[fullhash].hot-update.json',
|
|
106
106
|
strictModuleExceptionHandling: true,
|
|
107
107
|
// crossOriginLoading: crossOrigin,
|
|
108
|
-
webassemblyModuleFilename: 'static/wasm/[modulehash:8].wasm'
|
|
108
|
+
webassemblyModuleFilename: 'static/wasm/[modulehash:8].wasm',
|
|
109
|
+
hashFunction: 'xxhash64',
|
|
110
|
+
hashDigestLength: 16
|
|
109
111
|
});
|
|
110
112
|
// Support for NODE_PATH
|
|
111
113
|
const nodePathList = (process.env.NODE_PATH || '')
|
|
@@ -144,8 +146,13 @@ function baseWebpackChain({ dev, outputDir, parcelCss, projectRoot, include, typ
|
|
|
144
146
|
.use('shuvi-swc-loader')
|
|
145
147
|
.loader('@shuvi/shuvi-swc-loader')
|
|
146
148
|
.options({
|
|
147
|
-
|
|
149
|
+
isServer: false,
|
|
150
|
+
experimental,
|
|
151
|
+
compiler,
|
|
152
|
+
supportedBrowsers: false,
|
|
153
|
+
swcCacheDir: path.join(cacheDir, 'swc')
|
|
148
154
|
});
|
|
155
|
+
config.resolve.alias.set('@swc/helpers', path.dirname(require.resolve(`@swc/helpers/package.json`)));
|
|
149
156
|
mainRule
|
|
150
157
|
.oneOf('media')
|
|
151
158
|
.exclude.merge([/\.(tsx|ts|js|cjs|mjs|jsx)$/, /\.html$/, /\.json$/])
|
|
@@ -218,8 +225,8 @@ function baseWebpackChain({ dev, outputDir, parcelCss, projectRoot, include, typ
|
|
|
218
225
|
if (dev) {
|
|
219
226
|
// For webpack-dev-middleware usage
|
|
220
227
|
config.watchOptions({
|
|
221
|
-
aggregateTimeout:
|
|
222
|
-
ignored: ['**/.git/**'
|
|
228
|
+
aggregateTimeout: 50,
|
|
229
|
+
ignored: ['**/.git/**']
|
|
223
230
|
});
|
|
224
231
|
config.set('infrastructureLogging', {
|
|
225
232
|
level: 'none'
|
|
@@ -31,7 +31,7 @@ function createNodeWebpackChain(options) {
|
|
|
31
31
|
.rule('main')
|
|
32
32
|
.oneOf('js')
|
|
33
33
|
.use('shuvi-swc-loader')
|
|
34
|
-
.tap(options => (Object.assign(Object.assign({}, options), {
|
|
34
|
+
.tap(options => (Object.assign(Object.assign({}, options), { isServer: true })));
|
|
35
35
|
chain.plugin('private/build-manifest').tap(([options]) => [
|
|
36
36
|
Object.assign(Object.assign({}, options), { modules: false })
|
|
37
37
|
]);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
2
|
+
import type * as webpackType from 'webpack';
|
|
2
3
|
import type { Configuration } from 'webpack';
|
|
3
4
|
import type WebpackChain from 'webpack-chain';
|
|
4
5
|
import { ShareConfig } from './bundler';
|
|
5
|
-
declare type IResolveWebpackModule = <T extends string>(path: T) => T extends `webpack/${infer R}` ? any : never;
|
|
6
|
+
declare type IResolveWebpackModule = <T extends string>(path: T) => T extends `webpack` ? typeof webpackType : T extends `webpack/${infer R}` ? any : never;
|
|
6
7
|
interface IOpts {
|
|
7
8
|
cwd?: string;
|
|
8
9
|
rootDir: string;
|
|
@@ -29,7 +30,6 @@ export declare class DynamicDll {
|
|
|
29
30
|
modifyWebpackChain: (chain: WebpackChain) => WebpackChain;
|
|
30
31
|
modifyWebpack: (config: Configuration) => Configuration;
|
|
31
32
|
private _buildDLL;
|
|
32
|
-
private _makeAsyncEntry;
|
|
33
33
|
private _getMFconfig;
|
|
34
34
|
}
|
|
35
35
|
export {};
|
|
@@ -24,6 +24,30 @@ const dynamic_dll_plugin_1 = require("./plugin/dynamic-dll-plugin");
|
|
|
24
24
|
const metadata_1 = require("./metadata");
|
|
25
25
|
const utils_1 = require("./utils");
|
|
26
26
|
const check_not_in_node_modules_1 = require("./helper/check-not-in-node-modules");
|
|
27
|
+
function makeAsyncEntry(entry) {
|
|
28
|
+
const asyncEntry = {};
|
|
29
|
+
const virtualModules = {};
|
|
30
|
+
const entryObject = ((0, utils_1.isString)(entry) || (0, utils_1.isArray)(entry)
|
|
31
|
+
? { main: [].concat(entry) }
|
|
32
|
+
: entry);
|
|
33
|
+
for (const key of Object.keys(entryObject)) {
|
|
34
|
+
const virtualPath = `./dynamic-dll-virtual-entry/${key}.js`;
|
|
35
|
+
const virtualContent = [];
|
|
36
|
+
const entryFiles = (0, utils_1.isArray)(entryObject[key])
|
|
37
|
+
? entryObject[key]
|
|
38
|
+
: [entryObject[key]];
|
|
39
|
+
for (let entry of entryFiles) {
|
|
40
|
+
(0, invariant_1.default)((0, utils_1.isString)(entry), 'wepback entry must be a string');
|
|
41
|
+
virtualContent.push(`import('${entry}');`);
|
|
42
|
+
}
|
|
43
|
+
virtualModules[virtualPath] = virtualContent.join('\n');
|
|
44
|
+
asyncEntry[key] = virtualPath;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
asyncEntry,
|
|
48
|
+
virtualModules
|
|
49
|
+
};
|
|
50
|
+
}
|
|
27
51
|
class DynamicDll {
|
|
28
52
|
constructor(opts) {
|
|
29
53
|
this._hasBuilt = false;
|
|
@@ -79,7 +103,7 @@ class DynamicDll {
|
|
|
79
103
|
acc[name] = entries[name].values();
|
|
80
104
|
return acc;
|
|
81
105
|
}, {});
|
|
82
|
-
const { asyncEntry, virtualModules } =
|
|
106
|
+
const { asyncEntry, virtualModules } = makeAsyncEntry(entry);
|
|
83
107
|
chain.entryPoints.clear();
|
|
84
108
|
chain.merge({
|
|
85
109
|
entry: asyncEntry
|
|
@@ -94,7 +118,7 @@ class DynamicDll {
|
|
|
94
118
|
return chain;
|
|
95
119
|
};
|
|
96
120
|
this.modifyWebpack = (config) => {
|
|
97
|
-
const { asyncEntry, virtualModules } =
|
|
121
|
+
const { asyncEntry, virtualModules } = makeAsyncEntry(config.entry);
|
|
98
122
|
config.entry = asyncEntry;
|
|
99
123
|
const webpack = this._resolveWebpackModule('webpack');
|
|
100
124
|
if (!config.plugins) {
|
|
@@ -135,30 +159,6 @@ class DynamicDll {
|
|
|
135
159
|
});
|
|
136
160
|
});
|
|
137
161
|
}
|
|
138
|
-
_makeAsyncEntry(entry) {
|
|
139
|
-
const asyncEntry = {};
|
|
140
|
-
const virtualModules = {};
|
|
141
|
-
const entryObject = ((0, utils_1.isString)(entry) || (0, utils_1.isArray)(entry)
|
|
142
|
-
? { main: [].concat(entry) }
|
|
143
|
-
: entry);
|
|
144
|
-
for (const key of Object.keys(entryObject)) {
|
|
145
|
-
const virtualPath = `./dynamic-dll-virtual-entry/${key}.js`;
|
|
146
|
-
const virtualContent = [];
|
|
147
|
-
const entryFiles = (0, utils_1.isArray)(entryObject[key])
|
|
148
|
-
? entryObject[key]
|
|
149
|
-
: [entryObject[key]];
|
|
150
|
-
for (let entry of entryFiles) {
|
|
151
|
-
(0, invariant_1.default)((0, utils_1.isString)(entry), 'wepback entry must be a string');
|
|
152
|
-
virtualContent.push(`import('${entry}');`);
|
|
153
|
-
}
|
|
154
|
-
virtualModules[virtualPath] = virtualContent.join('\n');
|
|
155
|
-
asyncEntry[key] = virtualPath;
|
|
156
|
-
}
|
|
157
|
-
return {
|
|
158
|
-
asyncEntry,
|
|
159
|
-
virtualModules
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
162
|
_getMFconfig() {
|
|
163
163
|
return {
|
|
164
164
|
name: '__',
|
package/lib/webpack/index.d.ts
CHANGED
|
@@ -7,9 +7,9 @@ export { DynamicDll } from './dynamic-dll';
|
|
|
7
7
|
*/
|
|
8
8
|
export { webpack, validate, validateSchema, version, cli, ModuleFilenameHelpers, RuntimeGlobals, UsageState, WebpackOptionsValidationError, ValidationError, cache, config, dependencies, ids, javascript, optimize, runtime, prefetch, web, webworker, node, electron, wasm, library, container, sharing, debug, util, sources, experiments, WebpackPluginFunction,
|
|
9
9
|
/** export */
|
|
10
|
-
AutomaticPrefetchPlugin, AsyncDependenciesBlock, BannerPlugin, Cache, Chunk, ChunkGraph, CleanPlugin, Compilation, Compiler, ConcatenationScope, ContextExclusionPlugin, ContextReplacementPlugin, DefinePlugin, DelegatedPlugin, Dependency, DllPlugin, DllReferencePlugin, DynamicEntryPlugin, EntryOptionPlugin, EntryPlugin, EnvironmentPlugin, EvalDevToolModulePlugin, EvalSourceMapDevToolPlugin, ExternalModule, ExternalsPlugin, Generator, HotUpdateChunk, HotModuleReplacementPlugin, IgnorePlugin, JavascriptModulesPlugin, LibManifestPlugin, LibraryTemplatePlugin, LoaderOptionsPlugin, LoaderTargetPlugin, Module, ModuleGraph, ModuleGraphConnection, NoEmitOnErrorsPlugin, NormalModule, NormalModuleReplacementPlugin, MultiCompiler, Parser, PrefetchPlugin, ProgressPlugin, ProvidePlugin, RuntimeModule, EntryPlugin as SingleEntryPlugin, SourceMapDevToolPlugin, Stats, Template, WatchIgnorePlugin, WebpackError, WebpackOptionsApply, WebpackOptionsDefaulter, Entry, EntryNormalized, EntryObject, LibraryOptions, ModuleOptions, ResolveOptions, RuleSetCondition, RuleSetConditionAbsolute, RuleSetRule, RuleSetUse, RuleSetUseItem, Configuration, WebpackOptionsNormalized, WebpackPluginInstance, Asset, AssetInfo, MultiStats, ParserState, Watching, StatsAsset, StatsChunk, StatsChunkGroup, StatsChunkOrigin, StatsCompilation, StatsError, StatsLogging, StatsLoggingEntry, StatsModule, StatsModuleIssuer, StatsModuleReason, StatsModuleTraceDependency, StatsModuleTraceItem, StatsProfile } from 'webpack';
|
|
10
|
+
AutomaticPrefetchPlugin, AsyncDependenciesBlock, BannerPlugin, Cache, Chunk, ChunkGraph, CleanPlugin, Compilation, Compiler, ConcatenationScope, ContextExclusionPlugin, ContextReplacementPlugin, DefinePlugin, DelegatedPlugin, Dependency, DllPlugin, DllReferencePlugin, DynamicEntryPlugin, EntryOptionPlugin, EntryPlugin, EnvironmentPlugin, EvalDevToolModulePlugin, EvalSourceMapDevToolPlugin, ExternalModule, ExternalsPlugin, Generator, HotUpdateChunk, HotModuleReplacementPlugin, IgnorePlugin, JavascriptModulesPlugin, LibManifestPlugin, LibraryTemplatePlugin, LoaderOptionsPlugin, LoaderTargetPlugin, Module, ModuleGraph, ModuleGraphConnection, NoEmitOnErrorsPlugin, NormalModule, NormalModuleReplacementPlugin, MultiCompiler, Parser, Plugin, PrefetchPlugin, ProgressPlugin, ProvidePlugin, RuntimeModule, EntryPlugin as SingleEntryPlugin, SourceMapDevToolPlugin, Stats, Template, WatchIgnorePlugin, WebpackError, WebpackOptionsApply, WebpackOptionsDefaulter, Entry, EntryNormalized, EntryObject, LibraryOptions, ModuleOptions, ResolveOptions, RuleSetCondition, RuleSetConditionAbsolute, RuleSetRule, RuleSetUse, RuleSetUseItem, Configuration, WebpackOptionsNormalized, WebpackPluginInstance, Asset, AssetInfo, MultiStats, ParserState, Watching, StatsAsset, StatsChunk, StatsChunkGroup, StatsChunkOrigin, StatsCompilation, StatsError, StatsLogging, StatsLoggingEntry, StatsModule, StatsModuleIssuer, StatsModuleReason, StatsModuleTraceDependency, StatsModuleTraceItem, StatsProfile } from 'webpack';
|
|
11
11
|
/**
|
|
12
12
|
* resolve webpack module for not shuvi plugin
|
|
13
13
|
*/
|
|
14
|
-
declare const
|
|
15
|
-
export {
|
|
14
|
+
declare const webpackResolveContext: string;
|
|
15
|
+
export { webpackResolveContext };
|
package/lib/webpack/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DllReferencePlugin = exports.DllPlugin = exports.Dependency = exports.DelegatedPlugin = exports.DefinePlugin = exports.ContextReplacementPlugin = exports.ContextExclusionPlugin = exports.ConcatenationScope = exports.Compiler = exports.Compilation = exports.CleanPlugin = exports.ChunkGraph = exports.Chunk = exports.Cache = exports.BannerPlugin = exports.AsyncDependenciesBlock = exports.AutomaticPrefetchPlugin = exports.experiments = exports.sources = exports.util = exports.debug = exports.sharing = exports.container = exports.library = exports.wasm = exports.electron = exports.node = exports.webworker = exports.web = exports.prefetch = exports.runtime = exports.optimize = exports.javascript = exports.ids = exports.dependencies = exports.config = exports.cache = exports.ValidationError = exports.WebpackOptionsValidationError = exports.UsageState = exports.RuntimeGlobals = exports.ModuleFilenameHelpers = exports.cli = exports.version = exports.validateSchema = exports.validate = exports.webpack = exports.DynamicDll = exports.WebpackChain = exports.default = void 0;
|
|
7
|
-
exports.
|
|
7
|
+
exports.webpackResolveContext = exports.Watching = exports.MultiStats = exports.WebpackOptionsDefaulter = exports.WebpackOptionsApply = exports.WebpackError = exports.WatchIgnorePlugin = exports.Template = exports.Stats = exports.SourceMapDevToolPlugin = exports.SingleEntryPlugin = exports.RuntimeModule = exports.ProvidePlugin = exports.ProgressPlugin = exports.PrefetchPlugin = exports.Parser = exports.MultiCompiler = exports.NormalModuleReplacementPlugin = exports.NormalModule = exports.NoEmitOnErrorsPlugin = exports.ModuleGraphConnection = exports.ModuleGraph = exports.Module = exports.LoaderTargetPlugin = exports.LoaderOptionsPlugin = exports.LibraryTemplatePlugin = exports.LibManifestPlugin = exports.JavascriptModulesPlugin = exports.IgnorePlugin = exports.HotModuleReplacementPlugin = exports.HotUpdateChunk = exports.Generator = exports.ExternalsPlugin = exports.ExternalModule = exports.EvalSourceMapDevToolPlugin = exports.EvalDevToolModulePlugin = exports.EnvironmentPlugin = exports.EntryPlugin = exports.EntryOptionPlugin = exports.DynamicEntryPlugin = void 0;
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const webpack_1 = __importDefault(require("webpack"));
|
|
10
10
|
exports.default = webpack_1.default;
|
|
@@ -106,5 +106,5 @@ Object.defineProperty(exports, "Watching", { enumerable: true, get: function ()
|
|
|
106
106
|
/**
|
|
107
107
|
* resolve webpack module for not shuvi plugin
|
|
108
108
|
*/
|
|
109
|
-
const
|
|
110
|
-
exports.
|
|
109
|
+
const webpackResolveContext = (0, path_1.join)((0, path_1.dirname)(require.resolve('webpack/package.json')), '../');
|
|
110
|
+
exports.webpackResolveContext = webpackResolveContext;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
export interface ICssSyntaxError {
|
|
2
|
+
source: string;
|
|
3
|
+
fileName: string;
|
|
4
|
+
loc: {
|
|
5
|
+
line: number;
|
|
6
|
+
column: number;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
1
9
|
export default class CssSyntaxError extends Error {
|
|
2
|
-
constructor(error:
|
|
3
|
-
stack: boolean;
|
|
10
|
+
constructor(error: ICssSyntaxError);
|
|
4
11
|
}
|
|
@@ -23,7 +23,7 @@ function showSourceCode(source, lineNo, columnNo) {
|
|
|
23
23
|
}
|
|
24
24
|
class CssSyntaxError extends Error {
|
|
25
25
|
constructor(error) {
|
|
26
|
-
super(
|
|
26
|
+
super();
|
|
27
27
|
const { source, fileName, loc } = error;
|
|
28
28
|
const { line, column } = loc;
|
|
29
29
|
this.message = `\n\n${this.message}\n\n`;
|
|
@@ -33,6 +33,7 @@ class CssSyntaxError extends Error {
|
|
|
33
33
|
}
|
|
34
34
|
this.message += `\n${showSourceCode(source, line, column)}\n`;
|
|
35
35
|
// We don't need stack https://github.com/postcss/postcss/blob/master/docs/guidelines/runner.md#31-dont-show-js-stack-for-csssyntaxerror
|
|
36
|
+
// @ts-ignore
|
|
36
37
|
this.stack = false;
|
|
37
38
|
}
|
|
38
39
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
declare type Obj = Record<string, any>;
|
|
2
|
+
export declare type LoaderSWCOptions = {
|
|
3
|
+
filename: string;
|
|
4
|
+
isServer: boolean;
|
|
5
|
+
isPageFile: boolean;
|
|
6
|
+
development: boolean;
|
|
7
|
+
minify: boolean | Obj;
|
|
8
|
+
hasReactRefresh: boolean;
|
|
9
|
+
supportedBrowsers: any[];
|
|
10
|
+
experimental: Obj;
|
|
11
|
+
compiler: Obj;
|
|
12
|
+
swcCacheDir: string;
|
|
13
|
+
keep: string[];
|
|
14
|
+
};
|
|
15
|
+
export declare function getParserOptions({ filename, compiler, ...rest }: {
|
|
16
|
+
filename: string;
|
|
17
|
+
compiler: Obj;
|
|
18
|
+
}): {
|
|
19
|
+
syntax: string;
|
|
20
|
+
dynamicImport: boolean;
|
|
21
|
+
decorators: boolean;
|
|
22
|
+
importAssertions: boolean;
|
|
23
|
+
};
|
|
24
|
+
export default function getLoaderSWCOptions({ filename, development, isServer, minify, isPageFile, hasReactRefresh, experimental, compiler, supportedBrowsers, swcCacheDir, keep }: LoaderSWCOptions): {
|
|
25
|
+
jsc: {
|
|
26
|
+
externalHelpers: boolean;
|
|
27
|
+
parser: {
|
|
28
|
+
syntax: string;
|
|
29
|
+
dynamicImport: boolean;
|
|
30
|
+
decorators: boolean;
|
|
31
|
+
importAssertions: boolean;
|
|
32
|
+
};
|
|
33
|
+
experimental: {
|
|
34
|
+
keepImportAssertions: boolean;
|
|
35
|
+
plugins: any;
|
|
36
|
+
cacheRoot: string;
|
|
37
|
+
};
|
|
38
|
+
transform: {
|
|
39
|
+
legacyDecorator: boolean;
|
|
40
|
+
decoratorMetadata: boolean;
|
|
41
|
+
useDefineForClassFields: boolean;
|
|
42
|
+
react: {
|
|
43
|
+
importSource: any;
|
|
44
|
+
runtime: string;
|
|
45
|
+
pragma: string;
|
|
46
|
+
pragmaFrag: string;
|
|
47
|
+
throwIfNamespace: boolean;
|
|
48
|
+
development: boolean;
|
|
49
|
+
useBuiltins: boolean;
|
|
50
|
+
refresh: boolean;
|
|
51
|
+
};
|
|
52
|
+
optimizer: {
|
|
53
|
+
simplify: boolean;
|
|
54
|
+
globals: {
|
|
55
|
+
typeofs: {
|
|
56
|
+
window: string;
|
|
57
|
+
};
|
|
58
|
+
envs: {
|
|
59
|
+
NODE_ENV: string;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
regenerator: {
|
|
64
|
+
importPath: string;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
minify: boolean | Obj;
|
|
69
|
+
isDevelopment: boolean;
|
|
70
|
+
isServer: boolean;
|
|
71
|
+
isPageFile: boolean;
|
|
72
|
+
shakeExports: {
|
|
73
|
+
ignore: string[];
|
|
74
|
+
} | null;
|
|
75
|
+
disableShuviDynamic: any;
|
|
76
|
+
cssModuleFlag: string;
|
|
77
|
+
sourceMaps: undefined;
|
|
78
|
+
styledComponents: any;
|
|
79
|
+
removeConsole: any;
|
|
80
|
+
reactRemoveProperties: any;
|
|
81
|
+
modularizeImports: any;
|
|
82
|
+
emotion: {
|
|
83
|
+
enabled: boolean;
|
|
84
|
+
autoLabel: boolean;
|
|
85
|
+
sourcemap: boolean;
|
|
86
|
+
labelFormat?: undefined;
|
|
87
|
+
} | {
|
|
88
|
+
enabled: boolean;
|
|
89
|
+
autoLabel: boolean;
|
|
90
|
+
labelFormat: any;
|
|
91
|
+
sourcemap: any;
|
|
92
|
+
} | null;
|
|
93
|
+
};
|
|
94
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.getParserOptions = void 0;
|
|
15
|
+
function getParserOptions(_a) {
|
|
16
|
+
var { filename, compiler } = _a, rest = __rest(_a, ["filename", "compiler"]);
|
|
17
|
+
const isTSFile = filename.endsWith('.ts');
|
|
18
|
+
const isTypeScript = isTSFile || filename.endsWith('.tsx');
|
|
19
|
+
const enableDecorators = Boolean(compiler === null || compiler === void 0 ? void 0 : compiler.experimentalDecorators);
|
|
20
|
+
return Object.assign(Object.assign({}, rest), { syntax: isTypeScript ? 'typescript' : 'ecmascript', dynamicImport: true, decorators: enableDecorators,
|
|
21
|
+
// Exclude regular TypeScript files from React transformation to prevent e.g. generic parameters and angle-bracket type assertion from being interpreted as JSX tags.
|
|
22
|
+
[isTypeScript ? 'tsx' : 'jsx']: !isTSFile, importAssertions: true });
|
|
23
|
+
}
|
|
24
|
+
exports.getParserOptions = getParserOptions;
|
|
25
|
+
function getBaseSWCOptions({ filename, isPageFile, minify, development, hasReactRefresh, isServer, experimental, compiler, swcCacheDir, keep }) {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
const parserConfig = getParserOptions({ filename, compiler });
|
|
28
|
+
const enableDecorators = Boolean(compiler === null || compiler === void 0 ? void 0 : compiler.experimentalDecorators);
|
|
29
|
+
const emitDecoratorMetadata = Boolean(compiler === null || compiler === void 0 ? void 0 : compiler.emitDecoratorMetadata);
|
|
30
|
+
const useDefineForClassFields = Boolean(compiler === null || compiler === void 0 ? void 0 : compiler.useDefineForClassFields);
|
|
31
|
+
const plugins = ((_a = experimental === null || experimental === void 0 ? void 0 : experimental.swcPlugins) !== null && _a !== void 0 ? _a : [])
|
|
32
|
+
.filter(Array.isArray)
|
|
33
|
+
.map(([name, options]) => [require.resolve(name), options]);
|
|
34
|
+
return {
|
|
35
|
+
jsc: {
|
|
36
|
+
externalHelpers: true,
|
|
37
|
+
parser: parserConfig,
|
|
38
|
+
experimental: {
|
|
39
|
+
keepImportAssertions: true,
|
|
40
|
+
plugins,
|
|
41
|
+
cacheRoot: swcCacheDir
|
|
42
|
+
},
|
|
43
|
+
transform: {
|
|
44
|
+
legacyDecorator: enableDecorators,
|
|
45
|
+
decoratorMetadata: emitDecoratorMetadata,
|
|
46
|
+
useDefineForClassFields: useDefineForClassFields,
|
|
47
|
+
react: {
|
|
48
|
+
importSource: (_b = compiler === null || compiler === void 0 ? void 0 : compiler.jsxImportSource) !== null && _b !== void 0 ? _b : ((compiler === null || compiler === void 0 ? void 0 : compiler.emotion) ? '@emotion/react' : 'react'),
|
|
49
|
+
runtime: 'automatic',
|
|
50
|
+
pragma: 'React.createElement',
|
|
51
|
+
pragmaFrag: 'React.Fragment',
|
|
52
|
+
throwIfNamespace: true,
|
|
53
|
+
development: !!development,
|
|
54
|
+
useBuiltins: true,
|
|
55
|
+
refresh: !!hasReactRefresh
|
|
56
|
+
},
|
|
57
|
+
optimizer: {
|
|
58
|
+
simplify: false,
|
|
59
|
+
globals: {
|
|
60
|
+
typeofs: {
|
|
61
|
+
window: isServer ? 'undefined' : 'object'
|
|
62
|
+
},
|
|
63
|
+
envs: {
|
|
64
|
+
NODE_ENV: development ? '"development"' : '"production"'
|
|
65
|
+
}
|
|
66
|
+
// TODO: handle process.browser to match babel replacing as well
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
regenerator: {
|
|
70
|
+
importPath: require.resolve('regenerator-runtime')
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
minify,
|
|
75
|
+
isDevelopment: development,
|
|
76
|
+
isServer,
|
|
77
|
+
isPageFile,
|
|
78
|
+
shakeExports: keep.length > 0 ? { ignore: keep } : null,
|
|
79
|
+
disableShuviDynamic: (compiler === null || compiler === void 0 ? void 0 : compiler.disableShuviDynamic) || false,
|
|
80
|
+
cssModuleFlag: 'cssmodules',
|
|
81
|
+
sourceMaps: undefined,
|
|
82
|
+
styledComponents: getStyledComponentsOptions(compiler, development),
|
|
83
|
+
removeConsole: compiler === null || compiler === void 0 ? void 0 : compiler.removeConsole,
|
|
84
|
+
reactRemoveProperties: compiler === null || compiler === void 0 ? void 0 : compiler.reactRemoveProperties,
|
|
85
|
+
modularizeImports: experimental === null || experimental === void 0 ? void 0 : experimental.modularizeImports,
|
|
86
|
+
emotion: getEmotionOptions(compiler, development)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function getStyledComponentsOptions(compiler, development) {
|
|
90
|
+
var _a;
|
|
91
|
+
let styledComponentsOptions = compiler === null || compiler === void 0 ? void 0 : compiler.styledComponents;
|
|
92
|
+
if (!styledComponentsOptions) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
return Object.assign(Object.assign({}, styledComponentsOptions), { displayName: (_a = styledComponentsOptions.displayName) !== null && _a !== void 0 ? _a : Boolean(development) });
|
|
96
|
+
}
|
|
97
|
+
function getEmotionOptions(compiler, development) {
|
|
98
|
+
var _a;
|
|
99
|
+
const emotion = compiler === null || compiler === void 0 ? void 0 : compiler.emotion;
|
|
100
|
+
if (!emotion) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
// default 'dev-only'
|
|
104
|
+
let autoLabel = !!development;
|
|
105
|
+
if (emotion === true) {
|
|
106
|
+
return {
|
|
107
|
+
enabled: true,
|
|
108
|
+
autoLabel,
|
|
109
|
+
sourcemap: autoLabel
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
switch (emotion.autoLabel) {
|
|
113
|
+
case 'never':
|
|
114
|
+
autoLabel = false;
|
|
115
|
+
break;
|
|
116
|
+
case 'always':
|
|
117
|
+
autoLabel = true;
|
|
118
|
+
break;
|
|
119
|
+
default:
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
enabled: true,
|
|
124
|
+
autoLabel,
|
|
125
|
+
labelFormat: emotion.labelFormat,
|
|
126
|
+
sourcemap: development ? (_a = emotion.sourceMap) !== null && _a !== void 0 ? _a : true : false
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function getLoaderSWCOptions({ filename, development, isServer, minify, isPageFile, hasReactRefresh, experimental, compiler, supportedBrowsers, swcCacheDir, keep }) {
|
|
130
|
+
let baseOptions = getBaseSWCOptions({
|
|
131
|
+
filename,
|
|
132
|
+
isPageFile,
|
|
133
|
+
development,
|
|
134
|
+
isServer,
|
|
135
|
+
minify,
|
|
136
|
+
hasReactRefresh,
|
|
137
|
+
experimental,
|
|
138
|
+
compiler,
|
|
139
|
+
swcCacheDir,
|
|
140
|
+
keep
|
|
141
|
+
});
|
|
142
|
+
if (isServer) {
|
|
143
|
+
baseOptions.env = {
|
|
144
|
+
targets: {
|
|
145
|
+
// Targets the current version of Node.js
|
|
146
|
+
node: process.versions.node
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
// Matches default @babel/preset-env behavior
|
|
152
|
+
baseOptions.jsc.target =
|
|
153
|
+
'es5';
|
|
154
|
+
if (supportedBrowsers && supportedBrowsers.length > 0) {
|
|
155
|
+
baseOptions.env = {
|
|
156
|
+
targets: supportedBrowsers
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return baseOptions;
|
|
161
|
+
}
|
|
162
|
+
exports.default = getLoaderSWCOptions;
|
|
File without changes
|