Webpack-将node_modules导入浏览器

我可以从.js以外的任何文件夹导入node_modules文件,但是当我尝试从node_modules导入时,所有代码都被破坏了。这是我的文件夹结构:

node_modules/
  lodash/
  jquery/
src/
  js/
    index.js
    other.js

webpack.config.js

工作代码:

// other.js

export default a = 10;

// index.js

import a from './other';
console.log(a); // 10
// other code works

无效代码:

import { VERSION } from "lodash";
import $ from "jquery";
console.log($('body'),VERSION); 
console.log('does this work?'); // didn't log anything

然后我尝试使用webpack进行通天塔,没有运气。这是我的webpack配置:

const path = require('path');

module.exports = {
  mode: 'development',entry: {
    index: './src/js/index.js',},output: {
    filename: 'bundle.js',publicPath: '/assets/',path: path.resolve('assets')
  },module: {
    rules: [
      {
        test: /\.js$/,exclude: /node_modules/,use: {
          loader: 'babel-loader',options: {
            cacheDirectory: true,presets: ['@babel/preset-env']
          }
        }
      },]
  },resolve: {
     extensions: ['.js']
  },};

我搜索解决方案超过一个星期。谁能帮我? 所有的东西都是最新的版本

ashinelee 回答:Webpack-将node_modules导入浏览器

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3151697.html

大家都在问