Webpack相对路径解决错误

时间:2016-07-26 19:29:10

标签: javascript node.js ecmascript-6 webpack babeljs

我导入了这样的模块import { validate } from '../../_lib'; 但是webpack会给我一个错误ModuleNotFoundError。在里面看来它似乎解析了错误的原因:resolve file c:/Users/Me/project/resource/func\\_lib doesn't exist

我的目录看起来像这样:

project
 resource
  func
   file.js
_lib
 validate.js
 index.js
validate.js中的

我导出了一个类似export function validate(){}的函数 并且index.js我导出的验证方式export * from './validate'

这是mt webpack config

var webpack = require('webpack');

module.exports = {
  // entry: provided by serverless
  // output: provided by serverless
  target: 'node',
  externals: [
    'aws-sdk',
    'dynamodb-doc'
  ],
  resolve: {
    extensions: ['', '.js', '.jsx']
  },
  devtool: 'source-map',
  plugins: [
    new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        unused: true,
        dead_code: true,
        warnings: false,
        drop_debugger: true
      }
    }),
        function () {
            this.plugin("done", function (stats) {
                if (stats.compilation.errors && stats.compilation.errors.length) {
                    console.error(stats.compilation.errors)
                    throw new Error(stats.compilation.errors);
                }
            });
        }
  ],
  module: {
    loaders: [
            {
        test: /\.json$/,
        loader: 'json'
      },
      {
        test: /\.html$/,
        loader: 'html'
      },
            {
        test: /\.js$/,
        loader: 'babel',
        exclude: /node_modules/,
        query: {
          presets: ['es2015', 'stage-0']
        }
      }
    ]
  }
};

0 个答案:

没有答案