npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flutter_split

v1.0.5

Published

flutter-web分包工具

Downloads

3

Readme

Flutter_split

flutter打包成web的时候main.dart.js文件有点大, 用这个分包成几个小一点的文件, 首页加载快很多

安装

npm i flutter_split -g

使用

在你的项目执行build命令结束之后,执行一下命令:

ant -s dist

dist 是你main.dart.js所在的文件夹, 比如 build, dist, 每个人的目录有可能不一样

配合文件

/dist/index.html加载main.dart.js的地方需要修改

 <!--<script src="main.dart.js" type="application/javascript"></script>-->
  <script>
    var serviceWorkerVersion = null;
    var scriptLoaded = false;
    var fileContent = null;
    function loadMainDartJs() {
      if (scriptLoaded) {
        return;
      }
      scriptLoaded = true;
      var scriptTag = document.createElement('script');
      scriptTag.src = 'main.dart.js';
      scriptTag.type = 'application/javascript';
      document.body.append(scriptTag);
    }

    //创建script标签 并加载内容
    function createScript(content) {
      var head = document.getElementsByTagName('head')[0];
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.onreadystatechange = function () {
        if (this.readyState == 'complete')
          callback();
      }
      script.onload = function () {
        callback();
      }
      // script.src = 'main.dart.js';
      script.textContent = content;
      head.appendChild(script);
    }

    // 请求回每一个文件的内容
    const xhr = new XMLHttpRequest();
    const okStatus = document.location.protocol === "file:" ? 0 : 200;

    function load(name) {
      xhr.open('GET', name, false);
      xhr.overrideMimeType("text/html;charset=utf-8");//默认为utf-8
      xhr.send(null);
      const result = xhr.status === okStatus ? xhr.responseText : null;
      if(xhr.status === okStatus) {
        fileContent = Promise.resolve(xhr.responseText)
        return true
      }
      return false;
      // return result ? Promise.resolve(result) : false
    }

    // 判断文件是否存在
    function isExistFile(filepath, filename) {
      console.log(filepath, filename);
      if (filepath == null || filename == null || filepath === "" || filename === "") {
        return false
      }
      var xmlhttp;
      if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
      } else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.open("GET", filepath + '/' + filename, false);
      xmlhttp.send();
      if (xmlhttp.readyState === 4) {
        if (xmlhttp.status === 200) return true; //url存在
        else if (xmlhttp.status === 404) return false; //url不存在
        else return false;//其他状态
      }
    }
    // 加载文件夹
    function loadDir(dir = '/part') {
      let num = 0;
      let result = [];
      let resultStr = '';

      while (load(dir + '/' + num + '.txt')) {
        result.push(fileContent)
        num++
      }

      Promise.all([...result]).then((resArr) => {
        resArr.forEach(text => {
          resultStr += `
      ${text}`
        })
        // console.log(resultStr, 'resultStrresultStr');
        if (resultStr.length === 0) {
          // 还是加载main.dart.js
          loadMainDartJs();
        } else {
          createScript(resultStr)
        }
      })

      // return resultStr
    }

    loadDir()
  </script>