webpack(一) 配置

1、entry  & outputjson

mode: 'development',
  // entry: './src/index',
  // entry: ['./src/index', './src/pollyfill'],
  entry: {
    app: './src/index',
    pollyfill: './src/pollyfill.js'
  },
  output: {
    filename: '[name].[hash:8].js',
    path: path.resolve(__dirname, 'dist'),
   publicPath: '/', },

 2、resolvepromise

  resolve: {
    extensions: ['.js', '.jsx', '.json'],
    alias: {
      '@': path.join(__dirname, '../', 'src'),
    }
  },

3、懶加載app

import() 原理是經過jsonp; 返回promisejsonp

const $el = document.createElement('div');
$el.className ='container';
$el.addEventListener('click', function(){
  import('./caltTest').then((res)=>{
    console.log(res.default);
  })
});
document.body.appendChild($el);

4、熱更新spa

devServer中增長hotOnly:truecode


5、定義環境變量blog

new Webpack.DefinePlugin({
      ENV: 'true',
      // SERVE: "'https://www.baidu.com'",
      UAT: JSON.stringify('uat'),
    }),
相關文章
相關標籤/搜索