Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

局部注册 按需引用 打包后的大小并没有减少 #206

Closed
w550 opened this issue Nov 2, 2017 · 11 comments
Closed

局部注册 按需引用 打包后的大小并没有减少 #206

w550 opened this issue Nov 2, 2017 · 11 comments

Comments

@w550
Copy link

w550 commented Nov 2, 2017

"vue-baidu-map": "^0.18.4",
局部注册没有减少文件大小

<template>
  <baidu-map class="bm-view" ak="YOUR_APP_KEY">
  </baidu-map>
</template>

<script>
import {BaiduMap} from 'vue-baidu-map'
export default {
  components: {
    BaiduMap
  }
}
</script>

<style>
.bm-view {
  width: 100%;
  height: 300px;
}
</style>
@Dafrok
Copy link
Owner

Dafrok commented Nov 2, 2017

如果你是用 webpack2 打包,它目前还不支持 UMD 模块的 tree shaking,这里还没进行处理,后续版本会根据你提出的这类需求单独 build 一份静态模块的包。

如果你目前急用的话,可以直接 import vue-baidu-map/src 文件夹下的独立组件,因为是静态模块所以 webpack 2 是可以 shaking 掉的。

@w550
Copy link
Author

w550 commented Nov 2, 2017

@Dafrok
抱歉忘记讲版本号了。我的webpack是3.6。

"dependencies": {
    "axios": "^0.16.2",
    "better-scroll": "^1.3.1",
    "bootstrap": "4.0.0-beta",
    "chart.js": "^2.7.0",
    "fastclick": "^1.0.6",
    "lrz": "^4.9.40",
    "postcss-write-svg": "jonathantneal/postcss-write-svg",
    "pug": "^2.0.0-rc.4",
    "vee-validate": "^2.0.0-rc.19",
    "vue": "^2.4.4",
    "vue-baidu-map": "^0.18.4",
    "vue-chartjs": "^3.0.0",
    "vue-infinite-loading": "^2.2.1",
    "vue-infinite-scroll": "^2.0.2",
    "vue-moment": "^2.0.2",
    "vue-router": "^2.7.0",
    "vue-touchfeedback": "^2.0.0",
    "vuex": "^2.4.0",
    "vux": "^2.6.5",
    "vux-loader": "^1.1.13"
  },
  "devDependencies": {
    "ajv": "^5.2.3",
    "autoprefixer": "^7.1.4",
    "babel-core": "^6.26.0",
    "babel-eslint": "^8.0.1",
    "babel-loader": "^7.1.2",
    "babel-plugin-istanbul": "^4.1.5",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.6.0",
    "babel-preset-stage-2": "^6.24.1",
    "babel-register": "^6.26.0",
    "chai": "^4.1.2",
    "chalk": "^2.1.0",
    "chromedriver": "^2.32.3",
    "connect-history-api-fallback": "^1.3.0",
    "copy-webpack-plugin": "^4.0.1",
    "cross-env": "^5.0.5",
    "cross-spawn": "^5.1.0",
    "css-loader": "^0.28.7",
    "cssnano": "^3.10.0",
    "eslint": "^4.7.2",
    "eslint-config-standard": "^10.2.1",
    "eslint-friendly-formatter": "^3.0.0",
    "eslint-loader": "^1.9.0",
    "eslint-plugin-html": "^3.2.2",
    "eslint-plugin-import": "^2.7.0",
    "eslint-plugin-node": "^5.1.1",
    "eslint-plugin-promise": "^3.5.0",
    "eslint-plugin-standard": "^3.0.1",
    "eventsource-polyfill": "^0.9.6",
    "express": "^4.15.5",
    "extract-text-webpack-plugin": "^3.0.0",
    "file-loader": "^0.11.2",
    "friendly-errors-webpack-plugin": "^1.6.1",
    "html-webpack-plugin": "^2.30.1",
    "http-proxy-middleware": "^0.17.4",
    "inject-loader": "^3.0.1",
    "karma": "^1.7.1",
    "karma-coverage": "^1.1.1",
    "karma-mocha": "^1.3.0",
    "karma-phantomjs-launcher": "^1.0.4",
    "karma-phantomjs-shim": "^1.5.0",
    "karma-sinon-chai": "^1.3.2",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-spec-reporter": "0.0.31",
    "karma-webpack": "^2.0.4",
    "less": "2.3.1",
    "less-loader": "^4.0.5",
    "mocha": "^3.5.3",
    "nightwatch": "^0.9.16",
    "node-sass": "^4.5.3",
    "opn": "^5.1.0",
    "optimize-css-assets-webpack-plugin": "^3.2.0",
    "ora": "^1.3.0",
    "phantomjs-prebuilt": "^2.1.15",
    "postcss-px-to-viewport": "^0.0.3",
    "rimraf": "^2.6.2",
    "sass-loader": "^6.0.6",
    "selenium-server": "^3.5.3",
    "semver": "^5.4.1",
    "shelljs": "^0.7.8",
    "sinon": "2.1.0",
    "sinon-chai": "^2.13.0",
    "url-loader": "^0.5.9",
    "vue-loader": "^13.0.5",
    "vue-style-loader": "^3.0.3",
    "vue-template-compiler": "^2.4.4",
    "webpack": "^3.6.0",
    "webpack-bundle-analyzer": "^2.9.0",
    "webpack-dev-middleware": "^1.12.0",
    "webpack-hot-middleware": "^2.19.1",
    "webpack-merge": "^4.1.0"
  },

@Dafrok
Copy link
Owner

Dafrok commented Nov 2, 2017

2 和 3 没什么本质区别,2 是指 2 以上的版本,我没表达清楚。这么区分是因为 1 压根就不支持 tree shaking。

@w550
Copy link
Author

w550 commented Nov 2, 2017

@Dafrok
好的。谢谢。支持加油。

@Dafrok
Copy link
Owner

Dafrok commented Dec 8, 2017

同步一下进度,babel 做 tree shaking 只能通过 plugin,我新开个项目搞。顺便上面问无关问题的我就删掉了,有问题请用 issue 生成器发。

Repository owner deleted a comment from CristalFJJ Dec 8, 2017
@hwen
Copy link
Contributor

hwen commented Dec 9, 2017

问一下,B大打算怎么实现这个。是类似 Element UI 那种,将组件都写在一个 package 里,然后通过 babel-plugin-component 来实现吗?

@Dafrok
Copy link
Owner

Dafrok commented Dec 9, 2017

如果不分包只能这么干,babel 还是太保守了😂

@Dafrok
Copy link
Owner

Dafrok commented Dec 18, 2017

突然觉得自己想多了,受到 rxjs 的启发发现其实直接 import 模块下的文件不就好了,反正只要是 es module 就能摇树,入口又不是只有一个 main

@Dafrok Dafrok closed this as completed in ffc0dec Jan 9, 2018
@Dafrok
Copy link
Owner

Dafrok commented Jan 9, 2018

0.20.0 版本更新了局部注册的方式,文档暂时还没有跟进,可以直接 import 'vue-baidu-map/components/相应的组件' 就可以注册了

@zouyaoji
Copy link
Contributor

不好意思,打扰题主问一下,局部注册时,load的include和exclude应该怎么设置?
我用的vue-cli模板,在webpack.base.conf.js折腾了好久了没成功。

ERROR in ./node_modules/vue-baidu-map/components/Map/Map.vue
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| <template>
| <div>
|   <div v-if="!hasBmView" ref="view" style="width: 100%; height: 100%;"></div>
 @ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/pages/contact/contact.vue 3:0-60
 @ ./src/components/pages/contact/contact.vue
 @ ./src/components lazy ^\.\/.*\.vue$
 @ ./src/router.js
 @ ./src/main.js
 @ multi ./build/hot-reload.js ./src/main.js
Child html-webpack-plugin for "index.html":

@zouyaoji
Copy link
Contributor

打扰了,不用理我了,另外init了一个模板好了,不知道我把哪儿改乱了……

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants