🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@para-snack/snack-scripts-test

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@para-snack/snack-scripts-test - npm Package Compare versions

Comparing version
0.0.2
to
0.0.3
+41
template/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<link rel="icon" href="favicon.ico"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta
name="description"
content="Paraview FED"
/>
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="app"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
<script>
window.devServer = '<%= htmlWebpackPlugin.options.jsvers.devServer %>';
window.SnacName = '<%= htmlWebpackPlugin.options.jsvers.name %>';
</script>
<script src="loader.js?_=<%= htmlWebpackPlugin.options.jshash %>"></script>
</html>
import React from 'react';
import ReactDOM from 'react-dom';
import {Debugger} from "para-lib";
const {SnackD, SnackCore, SnackName, devServer} = (window as any);
async function init() {
if (devServer)
await Debugger.init(devServer.split(','));
else
await SnackCore.Context.load();
await SnackD.SnackSDK({
'react': React,
'react-dom': ReactDOM
});
debugger
SnackD.sdk.module(SnackName, false, function (e) {
var module = e[SnackName + ''];
if (!module) alert('module SnackName ' + SnackName + ' error');
new module({}, document.getElementById('app'));
});
}
init();
console.log('123')
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>/*{name}*/</title>
/*{debugjs}*/
/*{lib}*/
<script src="/*{sdk}*/"></script>
</head>
<body>
<div id="app"></div>
</body>
<script>
var name = '/*{name}*/';
var Context = /*{context}*/;
function ok(result) {
window.sdk = new SnackCore.SDK(/*{origin}*/, {
'react': window.React,
'react-dom': window.ReactDOM
});
/*{modPath}*/
window.sdk.module(name, true, function (e) {
var module = e[name + 'setting'];
if (!module) alert('module name ' + name + ' error');
new module({}, {}, document.getElementById('app'));
});
}
function err(e) {
console.error('Snack Load Error', e);
}
</script>
</html>
+12
-22

@@ -18,2 +18,7 @@ #!/usr/bin/env node

const args = process.argv.slice(2);
const argv = minimist(args, {
default: {
project: null
}
});
const scriptIndex = args.findIndex(

@@ -26,13 +31,3 @@ x => x === 'build' || x === 'eject' || x === 'start' || x === 'test'

// 项目路径
let projectPath = process.cwd();
// 调试模式
if (script === 'test') {
const testProjectPath = args[scriptIndex + 1];
if (!testProjectPath) {
console.error('miss test project path');
process.exit();
}
projectPath = testProjectPath;
}
let projectPath = argv.project || process.cwd();
// webpack配置路径

@@ -45,3 +40,3 @@ const configPath = path.resolve(__dirname, `../config/webpack.config.js`);

case 'start':
argv = ['webpack-dev-server', '--host 127.0.0.1', `--config=${configPath}`];
argv = ['serve', '--mode=development', `--config=${configPath}`];
break;

@@ -52,18 +47,13 @@ case 'build':

case 'test':
argv = ['--mode=production', `--config=${configPath}`];
argv = ['--mode=development', `--config=${configPath}`];
break;
}
const ps = spawn('webpack', argv, {
cwd: projectPath
cwd: projectPath,
stdio: 'pipe'
});
ps.stdout.on('data', (data) => {
console.log('Snack-cli:', data.toString());
});
ps.stderr.on('data', (data) => {
console.warn('Snack-cli:', data.toString());
});
ps.stdout.pipe(process.stdout);
ps.stderr.pipe(process.stderr);
}
run(script);

@@ -5,2 +5,4 @@ const path = require('path');

const TerserPlugin = require('terser-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
/*获取命令行参数*/

@@ -12,3 +14,4 @@ const argv = minimist(process.argv.slice(2), {

});
const isDevelopment = argv.mode === 'development';
const isProduction = argv.mode === 'production';
/*

@@ -26,18 +29,41 @@ * package.json 扩展参数

const {GetPackageList, ReplaceDefine} = require(path.resolve(__dirname, '../utils/package'));
console.log('check snack package...');
const packageList = GetPackageList(packagePath);
// add entry
let entrys = {};
let plugins = [];
const plugins = [];
const coyps = [];
for (let i = 0, l = packageList.length; i < l; i++) {
const item = packageList[i];
entrys[item.name] = item.runtimeEntry;
entrys[`${item.name}/setting`] = item.entry;
// runtime entry
entrys[`${item.name}/index.js`] = item.runtimeEntry;
entrys[`${item.name}/loader.js`] = item.runtimeEntry;
coyps.push({
from: path.resolve(__dirname, '../utils/snack.sdk.js'),
to: path.resolve(outPath, item.name)
});
plugins.push(new HtmlWebpackPlugin({
chunks: [item.name, `${item.name}/loader.js`],
title: item.info.name,
filename: path.resolve(outPath, item.name, 'index.html'),
template: path.resolve(__dirname, '../template/index.html'),
hash: true,
inject: false,
jshash: String(Math.random() * 1000000 | 0) + String(Math.random() * 1000000 | 0),
jsvers: {
name: item.name,
devServer: isDevelopment ? packageJson.dev && packageJson.dev.debug.join(',') : null
}
}));
// all entry
entrys[`${item.name}/setting/index.js`] = item.entry;
}
console.log('remove output dir...');
fs.removeSync(outPath);
console.log('building...');
module.exports = {
entry: entrys,
devtool: isDevelopment ? 'cheap-module-source-map' : false,
output: {
filename: `[name]/index.js`,
filename: `[name]`,
path: outPath, // 要输出多文件这里就要配置输出目录而不是当个文件

@@ -49,3 +75,5 @@ library: 'Snack',

plugins: [
new ReplaceDefine()
new ReplaceDefine(),
new CopyWebpackPlugin({patterns: coyps}),
...plugins
],

@@ -89,24 +117,19 @@ // 过滤依赖包

// 需要下载 url-loader file-loader
loader: 'url-loader',
options: {
loader: 'url-loader'
/*options: {
// 图片大小小于8kb,就会被base64处理,优点:减少请求数量(减轻服务器压力),缺点:图片体积会更大(文件请求速度更慢)
// base64在客户端本地解码所以会减少服务器压力,如果图片过大还采用base64编码会导致cpu调用率上升,网页加载时变卡
limit: 1 * 1024,
limit: 8 * 1024,
// 给图片重命名,[hash:10]:取图片的hash的前10位,[ext]:取文件原来扩展名
name: '../../[path][name].[ext]',
name: '[path][name].[ext]?[hash]',
// 问题:因为url-loader默认使用es6模块化解析,而html-loader引入图片是conmonjs,解析时会出问题:[object Module]
// 解决:关闭url-loader的es6模块化,使用commonjs解析
esModule: false
}
}*/
},
{
test: /\.html$/,
// 处理html文件的img图片(负责引入img,从而能被url-loader进行处理)
loader: 'html-loader'
},
{
exclude: /\.(html|js|jsx|css|less|scss|sass|jpg|png|gif|ts|tsx)/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
name: '[name].[ext]?[hash]',
outputPath: 'images/'

@@ -133,5 +156,5 @@ }

contentBase: outPath,
compress: true,
hot: true,
open: true
}
};
{
"name": "@para-snack/snack-scripts-test",
"private": false,
"version": "0.0.2",
"version": "0.0.3",
"description": "snack-cli package scripts Powered by Para FED",

@@ -15,3 +15,5 @@ "bin": {

"scripts": {
"test": "node bin/main.js test /Users/hklmtt/Work/snack-cli",
"start": "node bin/main.js start --project=/Users/hklmtt/Work/snack-cli",
"build": "node bin/main.js build --project=/Users/hklmtt/Work/snack-cli",
"build:dev": "node bin/main.js test --project=/Users/hklmtt/Work/snack-cli",
"publish:npm": "npm publish"

@@ -26,12 +28,17 @@ },

"dependencies": {
"para-lib": "^1.4.12",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"snack-core": "^1.0.12"
},
"devDependencies": {
"copy-webpack-plugin": "^9.0.1",
"css-loader": "^3.4.2",
"file-loader": "^5.1.0",
"fs-extra": "^8.1.0",
"html-webpack-plugin": "^5.3.2",
"node-sass": "^4.13.1",
"sass-loader": "^8.0.2",
"style-loader": "^1.1.3",
"ts-loader": "^6.2.1",
"ts-loader": "^9.2.3",
"typescript": "^4.2.3",

@@ -38,0 +45,0 @@ "url-loader": "^3.0.0",