Skip to content
This repository has been archived by the owner on Dec 12, 2017. It is now read-only.

cooking 如何引入happypack #125

Closed
yelingfeng opened this issue Dec 15, 2016 · 4 comments
Closed

cooking 如何引入happypack #125

yelingfeng opened this issue Dec 15, 2016 · 4 comments
Labels

Comments

@yelingfeng
Copy link

目前构建时间 要2分钟 想引入happypack 或者有没有优化的方案?
image

@QingWei-Li
Copy link
Contributor

QingWei-Li commented Dec 15, 2016

happypack 似乎无视 vue-loader。我的做法是尽可能第三方库都用 cdn;用 buble 替代 babel

这是我最近在写的一个项目的配置,供参考

var resolve = require('path').resolve;
var cooking = require('cooking');

cooking.set({
  entry: './src/entry.js',
  dist: './dist',
  template: './index.tpl',
  devServer: {
    port: 8099,
    host: '0.0.0.0',
    proxy: {
      '/api': {
        target: 'http://localhost:7790',
        changeOrigin: true,
        pathRewrite: { '^/api': '' }
      }
    }
  },
  clean: true,
  hash: true,
  sourceMap: true,
  minimize: true,
  chunk: true,
  publicPath: '/',
  extractCSS: true,
  alias: {
    src: resolve(__dirname, 'src')
  },
  externals: process.env.NODE_ENV === 'production' ? {
    vue: 'Vue',
    vuex: 'Vuex',
    'vue-router': 'VueRouter',
    'element-ui': 'ELEMENT'
  } : {},
  extends: ['vue2', 'buble', 'lint', 'saladcss']
});

module.exports = cooking.resolve();

index.tpl (cdn 地址已隐去)

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>xxx</title>
  </head>
  <body>
    <div id="app"></div><% if (process.env.NODE_ENV === 'production') { %>
    <script src="//cdn.com/inexorabletash/polyfill/v0.1.27/polyfill.min.js"></script>
    <script src="//cdn.com/vuejs/vue/v__version__/dist/vue.runtime.min.js"></script>
    <script src="//npm.cdn/element-ui@__version__/lib/index.js"></script>
    <script src="//cdn.com/vuejs/vuex/v__version__/dist/vuex.min.js"></script>
    <script src="//cdn.com/vuejs/vue-router/v__version__/dist/vue-router.min.js"></script><% } %>
  </body>
</html>

然后自己写了个脚本替换 __version__

这个项目 build 用时也就 20 来秒,启动只用 10 秒

@yelingfeng
Copy link
Author

我们是内部系统 不能用cdn比较特殊
而且我用cooking-buble 在我使用vue-class-component的情况下 @component会报错
你的2个优化点 我没法渗透 :(

@QingWei-Li
Copy link
Contributor

那可以用 dllPlugin 把第三方库单独打包,build 花的时间基本上都是其他库的压缩和合并

@yelingfeng
Copy link
Author

好的 谢谢 QingWei大神 万分感谢

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

No branches or pull requests

2 participants