webpack笔记

打包 img src

src 必须以 点(.) 开始,才能被打包。 如:

  • ./img/logo.png
  • ../img/logo.png

使用 process

a.js

window.Base_Url = process.env.Base_Url;

编译结果:
window.Base_Url = "http://a.com"

会变为指定的值.

.babelrc

"env": {
    "test": {
      "presets": ["env", "stage-2"],
      "plugins": [ "istanbul" ]
    }
  }

以上代码指定了 test 是 process.env.NODE_ENV == "test" 的条件.它会寻找: .babelrc.env.test 文件 .报错内容:
Uncaught Error: Module build failed: ReferenceError: Unknown plugin "istanbul" specified in "/home/udi/IdeaProjects/pzx_vue2/.babelrc.env.test" at 0, attempted to resolve relative to "/home/udi/IdeaProjects/pzx_vue2"

编写Webpack 插件

http://www.css88.com/doc/webpack2/development/how-to-write-a-plugin/

组件中使用 jquery ,但不打包jquery

  1. 组件中
plugins: [
    new webpack.ProvidePlugin({// 全局依赖jQuery,不需要import了
      $: 'jquery/src/jquery',
      jQuery: 'jquery/src/jquery',
      'window.jQuery': 'jquery/src/jquery',
      'window.$': 'jquery/src/jquery',
    })
  ],
  externals: {
    vue: {
      root: 'Vue',
      commonjs: 'vue',
      commonjs2: 'vue',
      amd: 'vue'
    }
    , 'jquery': 'window.jQuery'
  },

项目中遇到问题: Error: Can't resolve 'window.jQuery' 参考答案: https://stackoverflow.com/questions/49546793/cant-resolve-jquery-with-typescript

  1. 项目中
原文地址:https://www.cnblogs.com/newsea/p/7684486.html