@snack-kit/scripts 0.8.0 → 0.9.0
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/README.md +14 -3
- package/bin/snack-scripts.js +5 -4
- package/config/webpack.dev.config.js +1 -1
- package/config/webpack.shared.js +20 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -156,11 +156,17 @@ src/package/UserManager/
|
|
|
156
156
|
|
|
157
157
|
## config-overrides.js
|
|
158
158
|
|
|
159
|
-
在项目根目录创建 `config-overrides.js` 可自定义 webpack
|
|
159
|
+
在项目根目录创建 `config-overrides.js` 可自定义 webpack 配置。
|
|
160
|
+
|
|
161
|
+
> **注意:** `snack-scripts` 会将已解析的 webpack 实例作为**第二参数**传入。若需使用 webpack 内置插件(如 `ProvidePlugin`),必须使用该参数而非 `require('webpack')`,否则会因 tapable 多实例冲突导致构建报错。
|
|
160
162
|
|
|
161
163
|
```js
|
|
162
|
-
module.exports = (config) => {
|
|
163
|
-
//
|
|
164
|
+
module.exports = (config, webpack) => {
|
|
165
|
+
// 使用传入的 webpack 实例,而非 require('webpack')
|
|
166
|
+
config.plugins = [
|
|
167
|
+
...config.plugins,
|
|
168
|
+
new webpack.ProvidePlugin({ /* ... */ }),
|
|
169
|
+
];
|
|
164
170
|
return config;
|
|
165
171
|
};
|
|
166
172
|
```
|
|
@@ -183,6 +189,11 @@ module.exports = (config) => {
|
|
|
183
189
|
|
|
184
190
|
## Changelog
|
|
185
191
|
|
|
192
|
+
### 0.9.0
|
|
193
|
+
|
|
194
|
+
- 修复:sass-loader 改回 legacy API,解决旧项目 `@import '~xxx'` 路径无法解析的问题(`api: 'modern'` 的 webpack importer 在 sass-loader 13.x 中未实现)
|
|
195
|
+
- 优化:添加 `silenceDeprecations` 配置,屏蔽 Dart Sass 1.80+ 对 `@import`、legacy JS API 等语法的弃用警告,迁移期间无需修改 SCSS 源文件
|
|
196
|
+
|
|
186
197
|
### 0.8.0
|
|
187
198
|
|
|
188
199
|
- 重构:`bin/main.js` 拆分为 `snack-cli`(init / create)和 `snack-scripts`(start / build / entry)两个独立命令
|
package/bin/snack-scripts.js
CHANGED
|
@@ -36,15 +36,16 @@ const entryConfigPath = path.resolve(__dirname, '../config/webpack.entry.config.
|
|
|
36
36
|
|
|
37
37
|
const platform = process.platform;
|
|
38
38
|
const webpackFile = platform === 'win32' ? 'webpack.cmd' : 'webpack';
|
|
39
|
-
|
|
39
|
+
|
|
40
|
+
// 始终使用 snack-scripts 自身内置的 webpack CLI,保证 CLI 进程与配置文件加载同一 webpack 实例,
|
|
41
|
+
// 避免与宿主项目 node_modules 中的 webpack 产生多实例 tapable 冲突。
|
|
42
|
+
const webpackBin = path.resolve(__dirname, '../node_modules/.bin/', webpackFile);
|
|
40
43
|
|
|
41
44
|
// ─── webpack 构建命令 ─────────────────────────────────────────────────────────
|
|
42
45
|
|
|
43
46
|
function execWebpack(wpArgs) {
|
|
44
47
|
return new Promise(resolve => {
|
|
45
|
-
const ps =
|
|
46
|
-
? spawn('webpack', wpArgs, { stdio: 'inherit', shell: true })
|
|
47
|
-
: spawn(path.resolve(__dirname, '../node_modules/.bin/', webpackFile), wpArgs, { stdio: 'inherit' });
|
|
48
|
+
const ps = spawn(webpackBin, wpArgs, { stdio: 'inherit' });
|
|
48
49
|
ps.on('error', e => { console.log(e); resolve(false); });
|
|
49
50
|
ps.on('exit', () => resolve(true));
|
|
50
51
|
});
|
|
@@ -100,7 +100,7 @@ const configOverridesPath = path.resolve(process.env.PROJECT_PATH, 'config-overr
|
|
|
100
100
|
if (fs.existsSync(configOverridesPath)) {
|
|
101
101
|
try {
|
|
102
102
|
const overrides = require(configOverridesPath);
|
|
103
|
-
conf = overrides(conf);
|
|
103
|
+
conf = overrides(conf, webpack);
|
|
104
104
|
console.log('snack config overrides');
|
|
105
105
|
} catch (err) {
|
|
106
106
|
console.error('SnackCLI Error:', err);
|
package/config/webpack.shared.js
CHANGED
|
@@ -151,7 +151,22 @@ function createSwcRule(withRefresh = false) {
|
|
|
151
151
|
*/
|
|
152
152
|
const styleRule = {
|
|
153
153
|
test: /\.(css|sass|scss)$/,
|
|
154
|
-
use: [
|
|
154
|
+
use: [
|
|
155
|
+
'style-loader',
|
|
156
|
+
'css-loader',
|
|
157
|
+
{
|
|
158
|
+
loader: 'sass-loader',
|
|
159
|
+
options: {
|
|
160
|
+
// 使用 legacy API:getModernWebpackImporter 在 sass-loader 13.x 中未实现,
|
|
161
|
+
// 导致 @import '~xxx' 的 ~ 前缀无法解析;legacy API 有完整的 webpack resolver 支持
|
|
162
|
+
webpackImporter: true,
|
|
163
|
+
sassOptions: {
|
|
164
|
+
// 屏蔽 Dart Sass 1.80+ 对 @import 语法的弃用警告,旧项目迁移期间无需修改 SCSS
|
|
165
|
+
silenceDeprecations: ['import', 'global-builtin', 'color-functions', 'legacy-js-api']
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
]
|
|
155
170
|
};
|
|
156
171
|
|
|
157
172
|
/**
|
|
@@ -219,17 +234,12 @@ const filesystemCache = {
|
|
|
219
234
|
};
|
|
220
235
|
|
|
221
236
|
/**
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
237
|
+
* 获取 webpack 实例。
|
|
238
|
+
* 始终使用 snack-scripts 自身内置的 webpack,保证 CLI 进程与 config 文件加载同一个实例,
|
|
239
|
+
* 避免与宿主项目 node_modules 中的 webpack 产生多实例 tapable 冲突。
|
|
225
240
|
*/
|
|
226
241
|
function resolveProjectWebpack() {
|
|
227
|
-
|
|
228
|
-
try {
|
|
229
|
-
return require(require.resolve('webpack', { paths: searchPaths }));
|
|
230
|
-
} catch (_) {
|
|
231
|
-
return require('webpack');
|
|
232
|
-
}
|
|
242
|
+
return require('webpack');
|
|
233
243
|
}
|
|
234
244
|
|
|
235
245
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snack-kit/scripts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "snack-cli package scripts Powered by Para FED",
|
|
5
5
|
"bin": {
|
|
6
6
|
"snack-cli": "./bin/snack-cli.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"tsconfig.json"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"dev:start": "node bin/snack-scripts.js start --project=/Users/liujia/工作/snack/
|
|
19
|
+
"dev:start": "node bin/snack-scripts.js start --project=/Users/liujia/工作/snack/pam-snack",
|
|
20
20
|
"dev:build": "node bin/snack-scripts.js build --project=/Users/liujia/工作/snack3-test",
|
|
21
21
|
"release": "npm publish --access public",
|
|
22
22
|
"release:beta": "npm publish --tag=beta --access public",
|