当前位置: 代码迷 >> JavaScript >> 导出功能将加载整个文件
  详细解决方案

导出功能将加载整个文件

热度:88   发布时间:2023-06-05 09:36:19.0

我认为通过导出特定的函数并使用它,它将仅将此函数包括在编译文件中,但似乎并不像以前那样:

文件1:

export function redu1(state = null, action) {
    return state;
}

export function redu2(state = null, action) {
    return state;
}

文件2:

import {redu1} from './file1';

我在编译文件中看到所有功能都包括在内了吗?

根据 ,您应该在webpack.config.js文件中将属性mode设置为production ,以从包中删除无效代码。

const path = require('path');

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  },

  mode: 'production'
};
  相关解决方案