Giter Site home page Giter Site logo

fis3-packager-deps-pack's Introduction

fis3-packager-deps-pack

支持包含依赖的打包方式。

fis.match('::packager', {
  packager: fis.plugin('deps-pack', {

    'pkg/hello.js': [

      // 将 main.js 加入队列
      '/static/hello/src/main.js',

      // main.js 的所有同步依赖加入队列
      '/static/hello/src/main.js:deps',

      // 将 main.js 所以异步依赖加入队列
      '/static/hello/src/main.js:asyncs',

      // 移除 comp.js 所有同步依赖
      '!/static/hello/src/comp.js:deps'
    ],

    // 也可以从将 js 依赖中 css 命中。
    'pkg/hello.css': [
      // main.js 的所有同步依赖加入队列
      '/static/hello/src/main.js:deps',
    ]

  })
});
  • 原来的 packTo 将被忽视,在此插件配置项中设置。
  • 每个规则都会按顺序将命中的文件加入到列表或者从列表中移除,顺序不同会带来不一样的结果。
  • :deps 用来命中目标文件的依赖文件,不包含自己。
  • :asyncs 用来命中目标文件的异步依赖,不包含自己。
  • !xxx 叹号打头的规则,会把命中的文件,从现有的列表中去除。

注意

同一个文件不能够打包到不同包里面,所以如果发现某个文件没有按预期打包目标文件里面,你需要分析是不是打包其他包里面了。 策略为谁先命中先生效。

安装

npm install -g fis3-packager-deps-pack

配置项

  1. useTrack 默认 true。 是否将合并前的文件路径写入注释中,方便定位代码。
  2. useSourceMap 默认为 false。是否开启 souremap 功能。

关闭输出路径信息

默认打包后输出路径信息,便于调试.形式如下

/*!/components/underscore/underscore.js*/

可以在插件的配置中关闭路径信息输出

fis.match('::package', {
  packager: fis.plugin('deps-pack', {
    useTrack : false, // 是否输出路径信息,默认为 true
    'pkg/all.js': [
       '/modules/index.jsx',
       '/modules/index.jsx:deps'
    ]
  })
})

开启 SourceMap 功能

fis.match('::package', {
  packager: fis.plugin('deps-pack', {
    useSourceMap : true, // 合并后开启 SourceMap 功能。
    'pkg/all.js': [
       '/modules/index.jsx',
       '/modules/index.jsx:deps'
    ]
  })
})

fis3-packager-deps-pack's People

Contributors

2betop avatar dblate 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

Watchers

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

fis3-packager-deps-pack's Issues

打包依赖失败

fis-conf.js 里的代码:

fis.match('*.jsx', {
  parser: fis.plugin('babel'),
  rExt: 'js'
})

fis.match('::packager', {
  packager: fis.plugin('deps-pack', {
    'pkg/deps-app.js': [
      // 将 app.jsx 加入队列
      '/module/app.jsx',
      // app.jsx 的所有同步依赖加入队列
      '/module/app.jsx:deps'
    ]
  })
});

执行后报错了:

[ERROR] Cannot set property 'lastIndex' of undefined

 [DEBUG] 16:14:54.676 TypeError: Cannot set property 'lastIndex' of undefined
    at /usr/local/lib/node_modules/fis3-packager-deps-pack/index.js:80:21
    at Array.filter (native)
    at find (/usr/local/lib/node_modules/fis3-packager-deps-pack/index.js:79:22)
    at /usr/local/lib/node_modules/fis3-packager-deps-pack/index.js:128:20
    at Array.forEach (native)
    at /usr/local/lib/node_modules/fis3-packager-deps-pack/index.js:116:14
    at Array.forEach (native)
    at module.exports (/usr/local/lib/node_modules/fis3-packager-deps-pack/index.js:100:21)
    at cb (/usr/local/lib/node_modules/fis3/lib/release.js:153:5)
    at /usr/local/lib/node_modules/fis3/lib/util.js:1079:9

想了解下时什么原因?

是否支持ES6 import?

我的入口js使用了es6,也配置了es6-babel,-d的文件夹也能看到源文件es6 import已经被转成require,但deps-pack的合并仍是import?

useSourceMap : false 为什么不好用

我在配置文件里设置了 useSourceMap : false,

    packager: fis.plugin('deps-pack', {
     useSourceMap : false,
      'pkg/index.js': /*当有多条时,请用数组*/[
        'modules/index.jsx',
        'modules/index.jsx:deps', // 以及其所有依赖
      ]

但是release 后 html里还是出现了SourceMap

/*resourcemap*/
require.resourceMap({
  "res": {
    "node_modules/object-assign/index": {
      "url": "/node_modules/object-assign/index.js",
      "type": "js",
      "pkg": "p0"
    },
    "node_modules/react/lib/reactProdInvariant": {
      "url": "/node_modules/react/lib/reactProdInvariant.js",
      "type": "js",
      "pkg": "p0"
    },
    "node_modules/fbjs/lib/invariant": {
      "url": "/node_modules/fbjs/lib/invariant.js",
      "type": "js",
      "pkg": "p0"
    },
......

```js


请问是我那里写错了吗?

貌似不是问题

fis.match('::package', {
  packager: fis.plugin('deps-pack', {
     'pkg/shim/ie8.js': ['src/shim/ie8.js:deps']
  })
})

fis.match('pkg/shim/ie8.js', {
  release: 'assets/pkg/shim/ie8.js'
})
<script src="pkg/shim/ie8.js"></script>

并不会被替换

单文件打到多个包中

“单个文件只能打到一个包中” 确实精简,没有冗余,但是同一个文件被2个模块依赖,怎么处理了?
感觉还是需要一下适度的冗余。

Js依赖中有样式文件,如何打包?

map.json

"components/sessions/sessions.jsx": {
    "uri": "/static/components/sessions/sessions.js",
    "type": "js",
    "deps": [
        "components/sessions/sessions.scss",
        "components/sessions/login.jsx",
        "components/sessions/register.jsx",
        "module/fishui/mobile/dialog/dialog.js",
        "module/util/util.js"
    ]
},

fis-config:

fis.match('::packager', {
    packager: fis.plugin('deps-pack',{
        'pkg/all.js': [
            'components/sessions/sessions.jsx:deps'
        ],
        'pkg/all.css': [
            'components/sessions/sessions.jsx:deps'
        ]
    }),
})

但并没有输出pkg/all.css
css的pkg无法找到Js中的样式依赖吗?

reg.test is not a function

使用时报错了, reg.test is not a function

   packager: fis.plugin('deps-pack', {
        useTrack : true, // 是否输出路径信息,默认为 true
        'pkg/app.js': [
            '/static/main.js',
            '/static/main.js:deps',
            '!/modules/vendor/*.js'
        ]
    })

fis3 版本 3.3.30

packTo的一种打包配置(含$1这种正则匹配)如何转化为deps的配置

之前用packTo,用到了如下的配置:

fis.match('/components/(*)/(**).vue', {
  packTo: '/runtime/components/$1/$2Pack.js'
})

现在要换成deps-pack这个插件,该怎么写,看文档并没有找到简单的方法,莫非要每个vue都要列出来进行配置?

有这个问题主要是因为有些打包需要命中依赖,用到了*.js:deps这种语法,packTo并不支持,所以换成了deps-pack。

支持process.env.NODE_ENV打包不同的文件吗?

if (process.env.NODE_ENV === 'production') {
module.exports = require('./Root.prod')
} else if(process.env.NODE_ENV === 'dev'){
module.exports = require('./Root.dev')
}else{
module.exports = require('./Root.webpack')
}

如上代码,配置
'pkg/third.js': [
'/modules/index.jsx:deps',
'!/modules/**'
],
会同时打包上面的三个js,支持分别打包吗?

如何分离依赖

packager: fis.plugin('deps-pack', {
            'pkg/react.js': [
                'node_modules/react/dist/react.min.js',
                'node_modules/react-dom/dist/react-dom.min.js'
            ],
            'pkg/index.js': [
                'mod/pages/index/index.jsx',
                'mod/pages/index/index.jsx:deps',
                '!react:deps'
            ],
            'pkg/index.css': [
                'mod/pages/index/index.jsx:deps'
            ]
        })

像上面的示意代码中的那样,将react分离为一个独立的包?

如何合并

r.js合并的话。要声明path配置。把所有js静态资源的路径都写出来。。不知道这里要怎么识别我所打包的js文件所调用的第三方组件的路径呢?我尝试了用了一下。只是把我主文件打包而已。并没有把依赖的文件打包进来啊

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.