GithubHelp home page GithubHelp logo

elemefe / page-skeleton-webpack-plugin Goto Github PK

View Code? Open in Web Editor NEW
2.8K 46.0 395.0 24.42 MB

Webpack plugin to generate the skeleton page automatically

License: MIT License

Vue 13.02% JavaScript 85.76% HTML 0.98% CSS 0.24%
webpack-plugin puppeteer page-skeleton

page-skeleton-webpack-plugin's Introduction

mark text

🔆Automatically generate Skeleton Page🌙
A Webpack plugin helps you build better JavaScript application


Features

Page Skeleton is a webpack plugin.The purpose of the plugin is to generate the corresponding skeleton screen page according to different route pages in your project, and to pack the skeleton screen page into the corresponding static route page through webpack.

  • Support multiple loading animations
  • Preview on mobile
  • Support multiple routes
  • Can be customized, and also directly modify the skeleton page source code in the preview page
  • Almost zero configuration available

Loading animations

Spin Shine Chiaroscuro

speed up play

Examples

All examples are in the examples folder.

Installation

Use npm to install this plugin, and you also need to install html-webpack-plugin.

npm install --save-dev page-skeleton-webpack-plugin

npm install --save-dev html-webpack-plugin

Basic Use

Step 1:configration

After installing the plug-in according to the above tutorial, you need to configure the plugin so that the plugin can run normally. The plugin will perform different operations depending on the environment of the node. When NODE_ENV === 'development', the plug-in can perform operations for generating and writing skeleton pages.

const HtmlWebpackPlugin = require('html-webpack-plugin')
const { SkeletonPlugin } = require('page-skeleton-webpack-plugin')
const path = require('path')
const webpackConfig = {
  entry: 'index.js',
  output: {
    path: __dirname + '/dist',
    filename: 'index.bundle.js'
  },
  plugin: [
    new HtmlWebpackPlugin({
       // Your HtmlWebpackPlugin config
    }),
    new SkeletonPlugin({
        pathname: path.resolve(__dirname, `${customPath}`), // the path to store shell file
        staticDir: path.resolve(__dirname, './dist'), // the same as the `output.path`
        routes: ['/', '/search'], // Which routes you want to generate skeleton screen
    })
  ]
}

📔Since the plugin selects different operations based on the process.env.NODE_ENV environment variable, so you need to configurate environment variables in the scripts option in the package.json file as follows:

"scripts": {
  "dev": "cross-env NODE_ENV=development node server.js",
  "build": "rm -rf dist && cross-env NODE_ENV=production webpack --progress --hide-modules"
}

That is, setting NODE_ENV to development in the development environment and NODE_ENV to production in the production environment.

Step 2:Modify template index.html of html-webpack-plugin

Add comment <!-- shell --> in the root element of you application.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <!-- shell -->
  </div>
</body>
</html>

Step 3:Operations and write shell

In the development page, use CtrlOrCmd + enter to call out the plugin interactive interface, or enter the toggleBar callout interface in the browser's JavaScript console.

Click the button in the interactive interface to preview the skeleton page. This process may take about 20s. After the plugin is ready for the skeleton page, it will automatically open the preview page through the browser, as shown below.

Scan the QR code in the preview page to preview the skeleton page on the mobile phone. You can directly edit the source code on the preview page. Write the skeleton page into the shell.html file by clicking the Write button in the upper right corner.

Re-package the application with webpack. When the page is restarted, you can see the application's skeleton structure before getting the data.

Documents

Server Options

Option Type Required? Default Description
pathname String Yes None Where the shell.html file shoud be output.
staticDir String Yes None Path to output static route page
routes Array Yes None Route in routes will generate static route with skeleton screen, please refer to sale
Port String No 8989 The port of Page Skeleton server
debug Boolean No true Whether debug mode is enabled or not, when debug is true, the output of the headless Chromium console will be output on the terminal.
minify false or Object No See defaults The plug-in will uglify the generated shell.html file by default. You can pass html-minifier configuration parameters to mimify shell.html. When configured to false , the generated shell.html file is not uglified and the shell.html file is formatted.
logLevel String No info Which type of messages you want to print in terminal, the optional values are info, warn and default value is info.
quiet Boolean No false Whether to print messages on the terminal, when set to true, no messages are printed.
noInfo Boolean No false When the value is true, plugin will not print info message.
logTime Boolean No true Print formatted time before the message.

Skeleton Page Options

Option Type Required Default Description
loading String No spin Animations of skeleton page, enumerated values:spin chiaroscuro shine
text Object No See defaults The configuration object can be configured with a color field that determines the color of the text block in the skeleton page. The color value supports hexadecimal, RGB, and so on.
image Object No See defaults This configuration accepts 3 properties, color, shape, and shapeOpposite. Color and shape are used to determine the color and shape of the image block in the skeleton page. The color value supports hexadecimal and RGB. The shape supports two enumeration values, circle and rect. The shapeOpposite field takes an array. Each element in the array is a DOM selector. It is used to select the DOM element. The shape of the selected DOM will be opposite to the configured shape. For example, if the configuration is rect, the image block in the shapeOpposite will be In the skeleton page is displayed as a circle shape (circular), how to configure can refer to the default configuration at the end of this section.
button Object No See defaults This configuration accepts two fields, color and excludes. Color is used to determine the color of the button block in the skeleton page. excludes accepts an array. The elements in the array are DOM selectors used to select elements. The elements in the array will not be considered button blocks.
svg Object No See defaults This configuration accepts 3 fields, color, shape, and shapeOpposite. Color and shape are used to determine the color and shape of the svg block in the skeleton page. The color value supports hexadecimal and RGB, and also supports the transparent enumeration value. After setting to transparent, the svg block will be a transparent block. Shapes support two enumeration values, circle and rect. The shapeOpposite field accepts an array. Each element in the array is a DOM selector for selecting the DOM element. The shape of the selected DOM will be the opposite of the configured shape shape. For example, if the configuration is rect then the svg block in the shapeOpposite will be In the skeleton page is displayed as a circle shape (circular).
pseudo Object No See defaults This configuration accepts two fields, color and shape. Color is used to determine the color of the skeletal page that is treated as a pseudo-element block, and shape is used to set the shape of the pseudo-element block, accepting two enum values: circle and rect.
excludes Array No [] If you have an element that does not require skeleton processing, write the element's CSS selector in the array.
remove Array No [] If you have elements that need to be removed from the DOM are configured with a CSS selector that will be removed in DOM tree.
hide Array No [] Don't want to remove it, but hide the element by setting its transparency to 0 and config element's CSS selector in the array.
grayBlock Array No [] The elements in the array are CSS selectors. The selected element will be processed by the plug-in into a color block. The color of the color block is the same as the color of the button block. Internal elements will no longer be specially treated and text will be hidden.
cssUnit String No rem The enum values it accepts are rem, vw, vh, vmin, vmax.
decimal Number No 4 Config the decimal of the css value in the skeleton page (shell.html). The default value is 4.

Puppeteer Options

Options Type Required? Default Description
device String No iPhone 6 Plus Used to set which mobile device simulator to generate the skeleton page. Refer to puppeteer for configuration.
defer Number No 5000 Puppeteer starts the headless Chrome browser. The delay after opening the page is mainly to ensure that the page is fully loaded and the unit is ms.
cookie Array No [] Refer to puppeteer.
storagies Object No {} LocalStorage
sessionStoragies Object No {} SessionStorage

Default options

const pluginDefaultConfig = {
  port: '8989',
  text: {
    color: '#EEEEEE'
  },
  image: {
    shape: 'rect', // `rect` | `circle`
    color: '#EFEFEF',
    shapeOpposite: []
  },
  button: {
    color: '#EFEFEF',
    excludes: [] 
  },
  svg: {
    color: '#EFEFEF',
    shape: 'circle', // circle | rect
    shapeOpposite: []
  },
  pseudo: {
    color: '#EFEFEF', // or transparent
    shape: 'circle' // circle | rect
  },
  device: 'iPhone 6 Plus',
  debug: false,
  minify: {
    minifyCSS: { level: 2 },
    removeComments: true,
    removeAttributeQuotes: true,
    removeEmptyAttributes: false
  },
  defer: 5000,
  excludes: [],
  remove: [],
  hide: [],
  grayBlock: [],
  cookies: [],
  storagies: {},
  sessionStoragies: {},
  cssUnit: 'rem',
  decimal: 4,
  logLevel: 'info',
  quiet: false,
  noInfo: false,
  logTime: true
}

Contribution

The project is under active development. If you have any questions, please submit your issues. Please refer to the issue template to submit the issue. If you are fixing a bug in the issues, please discuss it in the issue before submit the PR. If it is a new feature, submit a feature-related issue first before submit the PR.

There are three main development folders in the project:

  • client: Used to communicate between development projects and plugin server.
  • preview: The code of the preview page.
  • src: plugin server code.
    • script: script to generate the skeleton page.

Special thanks to @Yasujizr who designed the banner of Page Skeleton.

Maintainer

Jocs

License

MIT.

Copyright (c) 2017-present, @ElemeFE

page-skeleton-webpack-plugin's People

Contributors

cloudyan avatar hankxdev avatar hiuyanchong avatar jocs avatar whu12yz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

page-skeleton-webpack-plugin's Issues

无法呼出交互接面

  1. 系统:windows10,浏览器chrome 69.0.3497,
  2. 项目使用了create-react-app的webpack4版本以及config-overrides扩展内置配置, skeletonPlugin 配置如下:
    const skeletonPlugin = () => {
    new SkeletonPlugin({
    pathname: path.resolve(__dirname, ./shell), // the path to store shell file
    staticDir: path.resolve(__dirname, './build'), // the same as the output.path
    routes: ['/'], // Which routes you want to generate skeleton screen
    port: '8989',
    loading: 'chiaroscuro',
    })
    }

package种script配置:"start": "npm-run-all -p watch-css start-js",

  1. 问题描述:
    项目启动后在页面直用ctrl+enter无效,在控制台数据toggleBar提示:Uncaught ReferenceError: toggleBar is not defined,并没有看到插件交互界面,是不是除了该插件浏览器还需要安装什么工具

  2. PS:实例也无法启动,包output.path这个是个undefined

vue-cli项目begin to generator skeleton screen后开始报错

Description

new SkeletonPlugin({ pathname: path.resolve(__dirname,../index.html), // the path to store shell file staticDir: path.resolve(__dirname, '../static'), // the same as the output.pathroutes: ['/home/find'], // Which routes you want to generate skeleton screen defer:20000 }),
偶尔会提示生成成功 但是骨架屏是空白的
tyd i 1p3yna c z v

请问一下,骨架屏显示和隐藏的时机是什么时候?

Description

[Description of the bug or feature]

Steps to reproduce

  1. [First step]
  2. [Second step]
  3. [and so on...]

Expected behavior: [What you expected to happen]

Actual behavior: [What actually happened]

Link to an example: [If you're reporting a bug that's not reproducible, please try to reproduce it on JSFiddle, JS Bin, CodePen or a similar service and paste a link here]

Plugin configration

for example:

new SkeletonPlugin({
  pathname: path.resolve(__dirname, `./src`),
  port: '7890',
  loading: 'spin',
  svg: {
    color: '#EFEFEF',
    shape: 'circle',
    shapeOpposite: ['.red']
  },
  image: {
    shape: 'rect', // `rect` | `circle`
    color: '#EFEFEF',
    shapeOpposite: ['.white']
  },
  pseudo: {
    color: '#EFEFEF', // or transparent
    shape: 'circle', // circle | rect
    shapeOpposite: ['.apple', '.pen']
  },
  button: {
    color: '#EFEFEF',
    excludes: ['.center a']
  },
  defer: 5000,
  excludes: [],
  remove: [],
  hide: ['.ag-text', '.ag-image'],
  grayBlock: ['#header'],
  cssUnit: 'vw',
  cookies: [{
    name: 'SID',
    value: 'xxxxxx',
    url: 'https://xx.xxx.xx'
  }, {
    name: 'USERID',
    value: 'xxxxxx',
    url: 'https://xx.xxx.xx'
  }]
})

Versions

  • Page Skeleton:
  • Webpack:

不同路由生成不同骨架图

现在我能实现的是首屏生成骨架图,在切换不同路由的时候似乎没有对应的骨架图生成,我想问如果让每个路由,或者指定路由生成骨架图要怎么实现

单页面内页骨架图

你好,大概看了下文档自己跑了下 发现这种只针对首页生成骨架图吧,像单页面的内页这时候局部渲染的话这里面生成的骨架图好像就用不上吧,后面会有这种计划做内页骨架图吗

使用yarn安装page-skeleton-webpack-plugin报错

他这意思是 还会去下个chrome吗

$ yarn add -D page-skeleton-webpack-plugin
yarn add v1.3.2
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
info [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[4/5] Linking dependencies...
[5/5] Building fresh packages...
[-/2] ⠁ waiting...
[2/2] ⠁ puppeteer
[-/2] ⠁ waiting...
[-/2] ⠁ waiting...
error D:\studySpace\webpackDemo\webpack_skeleton_01\skeleton_demo\node_modules\puppeteer: Command failed.
Exit code: 1
Command: node install.js
Arguments:
Directory: D:\studySpace\webpackDemo\webpack_skeleton_01\skeleton_demo\node_modules\puppeteer
Output:
ERROR: Failed to download Chromium r564778! Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" env variable to skip download.

yarn install 之后报错了

/node_modules/webpack-cli/bin/config-yargs.js:89
describe: optionsSchema.definitions.output.properties.path.description,
^

TypeError: Cannot read property 'properties' of undefined
at module.exports (/Users/zhengguorong/project/feature/page-skeleton-webpack-plugin/node_modules/webpack-cli/bin/config-yargs.js:89:48)
at /Users/zhengguorong/project/feature/page-skeleton-webpack-plugin/node_modules/webpack-cli/bin/webpack.js:60:27
at Object. (/Users/zhengguorong/project/feature/page-skeleton-webpack-plugin/node_modules/webpack-cli/bin/webpack.js:515:3)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)

当项目打包至生产环境,history需要配置302重定向,多路由时找不到对应路由骨架,请问如何解决?

Description

[Description of the bug or feature]

Steps to reproduce

  1. [First step]
  2. [Second step]
  3. [and so on...]

Expected behavior: [What you expected to happen]

Actual behavior: [What actually happened]

Link to an example: [If you're reporting a bug that's not reproducible, please try to reproduce it on JSFiddle, JS Bin, CodePen or a similar service and paste a link here]

Plugin configration

for example:

new SkeletonPlugin({
  pathname: path.resolve(__dirname, `./src`),
  port: '7890',
  loading: 'spin',
  svg: {
    color: '#EFEFEF',
    shape: 'circle',
    shapeOpposite: ['.red']
  },
  image: {
    shape: 'rect', // `rect` | `circle`
    color: '#EFEFEF',
    shapeOpposite: ['.white']
  },
  pseudo: {
    color: '#EFEFEF', // or transparent
    shape: 'circle', // circle | rect
    shapeOpposite: ['.apple', '.pen']
  },
  button: {
    color: '#EFEFEF',
    excludes: ['.center a']
  },
  defer: 5000,
  excludes: [],
  remove: [],
  hide: ['.ag-text', '.ag-image'],
  grayBlock: ['#header'],
  cssUnit: 'vw',
  cookies: [{
    name: 'SID',
    value: 'xxxxxx',
    url: 'https://xx.xxx.xx'
  }, {
    name: 'USERID',
    value: 'xxxxxx',
    url: 'https://xx.xxx.xx'
  }]
})

Versions

  • Page Skeleton:
  • Webpack:

关于自动生成的骨架页面大小问题。

今天用demo项目跑了一下。发现生成的骨架页面平均大小都在80K左右( demo项目,结构和样式都还较少 )

如果已有项目引入这些生成的骨架页面的话,那么整个项目的体积会增加很多倍。这样反而让项目在生产环境运行时变慢。

目前看来采用骨架页面的体积劣势远不如直接采用loading。想问下饿了么团队有准备优化方案么?

page-skeleton-webpack-plugin安装报错

node-pre-gyp ERR! Tried to download(403): https://node-zopfli.s3.amazonaws.com/Release/zopfli-v2.0.2-node-v57-win32-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for [email protected] and [email protected] (node-v57 ABI, unknown) (falling back to source compile with node-gyp)
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack at PythonFinder.failNoPython (D:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:483:19)
gyp ERR! stack at PythonFinder. (D:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:508:16)
gyp ERR! stack at D:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:152:21)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "D:\Program Files\nodejs\node.exe" "D:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "configure" "--fallback-to-build" "--module=D:\work\gfresh
_vux\node_modules\node-zopfli\lib\binding\node-v57-win32-x64\zopfli.node" "--module_name=zopfli" "--module_path=D:\work\gfresh_vux\node_modules\node-zopfli\lib\binding\node-v57-win32-x64"
gyp ERR! cwd D:\work\gfresh_vux\node_modules\node-zopfli
gyp ERR! node -v v8.11.3
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute 'D:\Program Files\nodejs\node.exe D:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js configure --fallback-to-build --module=D:
work\gfresh_vux\node_modules\node-zopfli\lib\binding\node-v57-win32-x64\zopfli.node --module_name=zopfli --module_path=D:\work\gfresh_vux\node_modules\node-zopfli\lib\binding\node-v57-win32-x64' (1)
node-pre-gyp ERR! stack at ChildProcess. (D:\work\gfresh_vux\node_modules\node-pre-gyp\lib\util\compile.js:83:29)
node-pre-gyp ERR! stack at emitTwo (events.js:126:13)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:214:7)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:925:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
node-pre-gyp ERR! System Windows_NT #10.0.17134
node-pre-gyp ERR! command "D:\Program Files\nodejs\node.exe" "D:\work\gfresh_vux\node_modules\node-pre-gyp\bin\node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd D:\work\gfresh_vux\node_modules\node-zopfli
node-pre-gyp ERR! node -v v8.11.3
node-pre-gyp ERR! node-pre-gyp -v v0.6.39

ERROR: /static/js/bundle.js response.ok() is false

Description

image
image

error,response.ok() false
http://localhost:3000/static/js/bundle.js false

Plugin configration

for example:

new SkeletonPlugin({
      pathname: path.resolve(__dirname, './shell'), // the path to store shell file
      staticDir: path.resolve(__dirname, './build'), // the same as the `output.path`
      routes: ['/index', '/user', '/tool' ], // Which routes you want to generate skeleton screen
    }),

Versions

  • Page Skeleton: v0.10.12
  • Webpack: v3.8.1

How to run server in @vue/[email protected]

Description

add webpack plugin config in vue.config.js

const { SkeletonPlugin } = require("page-skeleton-webpack-plugin");
const path = require("path");
module.exports = {
  configureWebpack: {
    plugins: [
      new SkeletonPlugin({
        pathname: path.resolve(__dirname, "./shell"), // 用来存储 shell 文件的地址
        staticDir: path.resolve(__dirname, "./shelldist"), // 最好和 `output.path` 相同
        routes: ["/"] // 将需要生成骨架屏的路由添加到数组中
      })
    ]
  }
};

run yarn serve
output:

 ERROR  Failed to compile with 1 errors                                                                                                                                                    15:19:28

  TypeError: callback is not a function

  - skeletonPlugin.js:39 compilation.plugin
    [page-skeleton-webpack-plugin-demo]/[page-skeleton-webpack-plugin]/src/skeletonPlugin.js:39:7


  - index.js:165
    [page-skeleton-webpack-plugin-demo]/[preload-webpack-plugin]/build/index.js:165:15


  - index.js:165
    [page-skeleton-webpack-plugin-demo]/[preload-webpack-plugin]/build/index.js:165:15


  - new Promise


  - Hook.js:35 AsyncSeriesWaterfallHook.lazyCompileHook [as _promise]
    [page-skeleton-webpack-plugin-demo]/[tapable]/lib/Hook.js:35:21

  - index.js:673
    [page-skeleton-webpack-plugin-demo]/[html-webpack-plugin]/index.js:673:47

  - index.js:178 Promise.resolve.then.then.then.then.then.then.html
    [page-skeleton-webpack-plugin-demo]/[html-webpack-plugin]/index.js:178:18


  - next_tick.js:118 process._tickCallback
    internal/process/next_tick.js:118:7

Plugin configration

for example:

new SkeletonPlugin({
  pathname: path.resolve(__dirname, `./src`),
  port: '7890',
  loading: 'spin',
  svg: {
    color: '#EFEFEF',
    shape: 'circle',
    shapeOpposite: ['.red']
  },
  image: {
    shape: 'rect', // `rect` | `circle`
    color: '#EFEFEF',
    shapeOpposite: ['.white']
  },
  pseudo: {
    color: '#EFEFEF', // or transparent
    shape: 'circle', // circle | rect
    shapeOpposite: ['.apple', '.pen']
  },
  button: {
    color: '#EFEFEF',
    excludes: ['.center a']
  },
  defer: 5000,
  excludes: [],
  remove: [],
  hide: ['.ag-text', '.ag-image'],
  grayBlock: ['#header'],
  cssUnit: 'vw',
  cookies: [{
    name: 'SID',
    value: 'xxxxxx',
    url: 'https://xx.xxx.xx'
  }, {
    name: 'USERID',
    value: 'xxxxxx',
    url: 'https://xx.xxx.xx'
  }]
})

Versions

  • Page Skeleton: 0.10.1
  • Webpack: 3.12.0

vueCli3 下骨架屏无法注入

Description

  1. 下载vueCli3初始的项目 执行 npm install
  2. 运行 npm run serve ,项目正常运行,命令行也没有报错
  3. 然后调出控制条点击,生成preview,预览都ok,可以二维码预览,然后点击,写入shell文件目录
    image
  4. 结束 npm run serve.再次输入npm run serve,重新打包项目,在项目根目录下生成dist目录,然后打开项目,在开发环境下shell并没有注入

image

  1. 结束npm run serve,运行npm run build,dist目录被删除,重新写入dist的index.html在#app元素中没有注入骨架屏对应的html,在生产环境下也没有注入

Plugin configration

以下也是vue.config.js的所有配置

const path = require('path');
const { SkeletonPlugin } = require('page-skeleton-webpack-plugin');
module.exports = {
  configureWebpack: {
    plugins: [
      new SkeletonPlugin({
        pathname: path.resolve(__dirname, './shell'),
        staticDir: path.resolve(__dirname, './dist'),
        routes: ['/']
      })
    ]
  }
}

Versions

  • Page Skeleton: ^0.10.12
  • Webpack: webpack4.x
  • VueCli: 3.2.1

超时

Description

[Description of the bug or feature]

Steps to reproduce

  1. [First step]
  2. [Second step]
  3. [and so on...]

Expected behavior: [What you expected to happen]

Actual behavior: [What actually happened]

Link to an example: [If you're reporting a bug that's not reproducible, please try to reproduce it on JSFiddle, JS Bin, CodePen or a similar service and paste a link here]

Plugin configration

for example:

new SkeletonPlugin({
  pathname: path.resolve(__dirname, `./src`),
  port: '7890',
  loading: 'spin',
  svg: {
    color: '#EFEFEF',
    shape: 'circle',
    shapeOpposite: ['.red']
  },
  image: {
    shape: 'rect', // `rect` | `circle`
    color: '#EFEFEF',
    shapeOpposite: ['.white']
  },
  pseudo: {
    color: '#EFEFEF', // or transparent
    shape: 'circle', // circle | rect
    shapeOpposite: ['.apple', '.pen']
  },
  button: {
    color: '#EFEFEF',
    excludes: ['.center a']
  },
  defer: 5000,
  excludes: [],
  remove: [],
  hide: ['.ag-text', '.ag-image'],
  grayBlock: ['#header'],
  cssUnit: 'vw',
  cookies: [{
    name: 'SID',
    value: 'xxxxxx',
    url: 'https://xx.xxx.xx'
  }, {
    name: 'USERID',
    value: 'xxxxxx',
    url: 'https://xx.xxx.xx'
  }]
})

Versions

  • Page Skeleton:
  • Webpack:

不知道这个对路由的配置有什么要求

Description

1.我的路由配置大概是这样的,有个组件mobileLayout专门写了一些移动端的样式,作为嵌套路由
移动端都在这个组件里

{
    path: '',
    component: mobileLayout,
    children: [
{
        path: 'index',
        name: '列表页',
        component: () =>
          import ('@/views/home/index'),
        meta: {
          title: '大视VLOG',
          icon: ''
        },
      },
      {
        path: 'download',
        name: '下载页',
        component: () =>
          import ('@/views/download/index'),
        meta: {
          title: '大视VLOG',
          icon: ''
        },
      },
      {
        path: 'play',
        name: '视频详情',
        meta: {
          title: '大视VLOG'
        },
        props: (route) => ({
          query: route.query.videoId
        }),
        component: () =>
          import ('@/views/play/index')
      },
      {
        path: 'userCenter',
        name: '个人主页',
        meta: {
          title: '大视VLOG'
        },
        props: (route) => ({
          query: route.query.userId
        }),
        component: () =>
          import ('@/views/userCenter/index')
      }
    ]
}

什么也生成不出来,看了弹出的页面控制台报错了
报错图

2.如果我只配置很简单的路由,就可以生成了,但生成的骨架元素尺寸很有问题,并且高度填不满页面。

{
    path: '',
    name: 'root',
    component: mobileLayout,
    children: [{
      path: 'index',
      name: '列表页',
      component: () =>
        import ('@/views/home/index'),
      meta: {
        title: '大视VLOG',
        icon: ''
      },
    }]
}

请见图
尺寸错误

谢谢

Plugin configration

for example:

    new SkeletonPlugin({
      pathname: path.resolve(__dirname, './shell'), // the path to store shell file
      staticDir: path.resolve(__dirname, './dist'), // the same as the `output.path`
      routes: ['/', '/index','/play','/userCenter'], // Which routes you want to generate skeleton screen
      defer:20000,
      device:'iPhone X'
    }),

Versions

  • Page Skeleton:0.10.12
  • Webpack:3.6.0

webpack4 support and other features

  1. webpack4 的插件写法有改动哈,webpack4不支持
  2. 怎么实现multiple-page 骨架,路由配置好像只针对单页应用,能支持类似饿了么webapp这种多页面吗

关于源码学习的一个小问题

你好,我在看这个项目的源码,这是您第一提交的代码,index.js里,我有一个问题,就是在下面代码里,我打断点都走不进去,我想知道您在写这个项目的时候是怎么做调试的

const html = await page.evaluate((remove, excludes) => { 
    const $ = document.querySelectorAll
    if (remove.length) {
      const removeEle = $(remove.join(','))
      Array.from(removeEle).forEach(ele => ele.parentNode.removeChild(ele))
    }

    const excludesEle = excludes.length ? Array.from($(excludes.join(','))) : []
    const isBase64Img = img => /base64/.test(img.src)
    const imgs = []
    const texts = []
    const imgHandler = ele => {
      const div = document.createElement('div')
      const parent = ele.parentNode

      const { width, height } = ele.getBoundingClientRect()

      div.style.width = `${width}px`
      div.style.height = `${height}px`
      div.style.backgroundColor = '#efefef'

      parent.removeChild(ele)
      parent.appendChild(div)
    }
    const textHandler = ele => {
      const comStyle = window.getComputedStyle(ele)
      const { lineHeight, paddingTop, paddingRight, paddingBottom, position: opos, fontSize } = comStyle
      const position = ['fixed', 'absolute', 'flex'].find(p => p === opos) ? opos : 'relative'
      const height = ele.offsetHeight
      const lineCount = height / lineHeight | 0
      let textHeightRatio = parseInt(fontSize, 10) / parseInt(lineHeight, 10)
      if (Number.isNaN(textHeightRatio)) {
        textHeightRatio = 1 / 1.4
      }
      Object.assign(ele.style, {
        color: '#eee',
        backgroundImage: `linear-gradient(#fff ${(1 - textHeightRatio) / 2 * 100}%, #eee 0%, #eee ${((1 - textHeightRatio) / 2 + textHeightRatio) * 100}%, #fff 0%)`,
        backgroundSize: `100% ${lineHeight}px`,
        backgroundClip: 'content-box',
        backgroundPositionY: paddingTop,
        position
      })
      // add white mask
      if (lineCount > 1) {
        const div = document.createElement('div')

        Object.assign(div.style, {
          width: '50%',
          height: lineHeight,
          background: '#fff',
          position: 'absolute',
          right: paddingRight,
          bottom: paddingBottom
        })

        ele.appendChild(div)        
      }

    }

    const traverse = ele => {
      if (~excludesEle.indexOf(ele)) return false
      if (ele.tagName === 'IMG' && !isBase64Img(ele)) return imgs.push(ele)
      if (
        ele.childNodes
        && ele.childNodes.length === 1
        && ele.childNodes[0].nodeType === 3
        ) {
        return texts.push(ele)
      }

      if (ele.children && ele.children.length > 0) {
        Array.from(ele.children).forEach(child => traverse(child))
      }

    }

    traverse(document.documentElement)

    imgs.forEach(ele => imgHandler(ele))
    texts.forEach(ele => textHandler(ele))

    return document.documentElement.outerHTML

  }, remove, excludes)

  // browser.close()

  return { html }

Versions frist-commit

  • Page Skeleton:
  • Webpack:

项目跑不起来

直接clone项目然后npm install完了之后example里的项目跑不起来,报错
如下:
SkeletonPlugin.prototype.outputSkeletonScreen = async function () { // eslint-disable-line func-names

windows找不到chrome

Description

[Description of the bug or feature]

Steps to reproduce

  1. 开始之后可以到generator HTML
    tim 20180409112836

但是接下来就会报错,并且弹出windows找不到chrome
tim 20180409112046

chrome为最新版本
在同目录下,运行puppeteer的demo是可以唤出chrome
第一次配置skeleton,网上也搜不到相关的问题
如果有什么低级的错误,还请谅解

Versions

  • Page Skeleton: 0.7.0
  • Webpack: 3.6.0

page-skeleton-webpack-plugin安装失败!!!

Description

[yarn or npm 安装失败]

Steps to reproduce

  1. [First step]
  2. [Second step]
  3. [and so on...]

error /Users/simon/Private/Vue/v-ym-mall/node_modules/puppeteer: Command failed.
Exit code: 1
Command: node install.js
Arguments:
Directory: /Users/simon/Private/Vue/v-ym-mall/node_modules/puppeteer
Output:
ERROR: Failed to download Chromium r588429! Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" env variable to skip download.
{ Error: connect ETIMEDOUT 172.217.160.112:443
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '172.217.160.112',

Versions

  • Page Skeleton: 最新
  • Webpack: 4.0以上

[PSG] Protocol error (Page.navigate): Cannot navigate to invalid URL

Description

I had succeed to install the plugin and start it,but when i touch the "preview skeleton page",I got an error named on the title.I wander if this plugin not support hash url?

Steps to reproduce

  1. [First step]
  2. [Second step]
  3. [and so on...]

Expected behavior: [What you expected to happen]

Actual behavior: [What actually happened]

Link to an example: [If you're reporting a bug that's not reproducible, please try to reproduce it on JSFiddle, JS Bin, CodePen or a similar service and paste a link here]

Plugin configration

for example:

new SkeletonPlugin({
  pathname: path.resolve(__dirname, `./src`),
  port: '7890',
  loading: 'spin',
  svg: {
    color: '#EFEFEF',
    shape: 'circle',
    shapeOpposite: ['.red']
  },
  image: {
    shape: 'rect', // `rect` | `circle`
    color: '#EFEFEF',
    shapeOpposite: ['.white']
  },
  pseudo: {
    color: '#EFEFEF', // or transparent
    shape: 'circle', // circle | rect
    shapeOpposite: ['.apple', '.pen']
  },
  button: {
    color: '#EFEFEF',
    excludes: ['.center a']
  },
  defer: 5000,
  excludes: [],
  remove: [],
  hide: ['.ag-text', '.ag-image'],
  grayBlock: ['#header'],
  cssUnit: 'vw',
  cookies: [{
    name: 'SID',
    value: 'xxxxxx',
    url: 'https://xx.xxx.xx'
  }, {
    name: 'USERID',
    value: 'xxxxxx',
    url: 'https://xx.xxx.xx'
  }]
})

Versions

  • Page Skeleton:
  • Webpack:

TypeError: generate is not a function

Description

The page-skeleton-webpack-plugin was installed and configured using the project generated by the @vue/cli 3.0 scaffold, but the skeleton screen could not be generated when the project was run.

使用@vue/cli 3.0脚手架生成的项目,安装并配置了page-skeleton-webpack-plugin,但是在运行项目时无法生成skeleton screen

Steps to reproduce

  1. Generate project using vue/cli 3.0
  2. Install page-skeleton-webpack-plugin and configure it in vue.config.js
  3. Execute npm run serve to run the project
  4. Open the console and click on Preview skeleton page
  5. An error has occurred 😭 -> "[PSG] generate is not a function"
  1. 使用vue/cli 3.0生成项目
  2. 安装page-skeleton-webpack-plugin,并在vue.config.js进行相应的配置
  3. 执行npm run serve运行项目
  4. 打开控制台,点击Preview skeleton page
  5. 出现错误😭 -> "[PSG] generate is not a function"

Expected behavior:

Correct generation of skeleton screen.

正确的生成skeleton screen

Actual behavior:

An error message 😭 -> "[PSG] generate is not a function" has occurred and the debug skeleton screen cannot be previewed.

出现了错误提示😭 -> "[PSG] generate is not a function",无法预览调试skeleton screen

image

Plugin configration

const path = require('path');
const { SkeletonPlugin } = require('page-skeleton-webpack-plugin');

module.exports = {
  crossorigin: 'anonymous',
  integrity: true,
  configureWebpack: {
    plugins: [
      new SkeletonPlugin({
        pathname: path.resolve(__dirname, './shell'),
        staticDir: path.resolve(__dirname, './dist'),
        routes: ['/'],
      }),
    ],
  },
};

Versions

  • Page Skeleton: 0.10.12
  • Webpack: 4.17.1

control+enter后报错

-> "[PSG] Evaluation failed: TypeError: Cannot read property 'length' of undefined at forEach.type (:415:30) at Array.forEach () at traverse (:414:27) at genSkeleton (:518:5) at :3:7"

vue-cli3创建的项目在生成骨架代码的时候报错

vue-cli3创建的项目在生成骨架代码的时候报错,不知道怎么解决。

我执行的是yarn dev,没有任何报错,但是在生成骨架的时候,报错了,以下是报错信息

[19:07:29] i 「pswp」: write C:\Users\ecareyu\Projects\demo\js\vue3-spa\dist\index.html successfully in /
[19:07:36] i 「pswp」: begin to generator skeleton screen
[19:07:44] i 「pswp」: generator skeleton screen successfully
(node:14592) UnhandledPromiseRejectionWarning: Error: spawn cmd ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
    at onErrorNT (internal/child_process.js:362:16)
    at _combinedTickCallback (internal/process/next_tick.js:139:11)
    at process._tickCallback (internal/process/next_tick.js:181:9)
(node:14592) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)ith .catch(). (rejection id: 1)
(node:14592) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Plugin configration

const { SkeletonPlugin } = require('page-skeleton-webpack-plugin')
const path = require('path')

module.exports = {
  configureWebpack: {
    plugins: [
      // vue-cli3自带html-webpack-plugin,所以我这边没有引入
      // 骨架屏插件
      new SkeletonPlugin({
        pathname: path.resolve(__dirname, './shell'),
        staticDir: path.resolve(__dirname, './dist'),
        routes: ['/'],
        port: '7890'
      })
    ]
  }
}

Versions

  • Page Skeleton: 0.10.12
  • Webpack:4.15.1
  • html-webpack-plugin:3.2.0

npm install failed

npm install error

npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning ECONNRESET: request to https://registry.npmjs.org/@types%2fnode failed, reason: read ECONNRESET
npm WARN registry Using stale package data from https://registry.npmjs.org/ due to a request error during revalidation.
npm ERR! code ETARGET
npm ERR! notarget No matching version found for @types/node@^10.11.7
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'editorconfig'
npm ERR! notarget

React使用该项目时,有一些问题

React版本16+
React使用该项目时,有一些问题:

  1. routes只能一个一个加入,添加多个,就无法生成骨架屏
  2. 骨架页面预览没有界面显示,只有白屏,代码区也没有代码,也是空白

Cannot read property 'tapAsync' of undefined

Description

使用create-react-app 新建的项目,然后尝试了一下,报了Cannot read property 'tapAsync' of undefined 的错误。

还是说,需要什么特别注意的设置?

端口号

image

本地没有这个端口号的服务,排除端口号被占用的可能。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.