Webpack2无法找到预设的es2015或做出反应

时间:2017-01-09 12:10:28

标签: javascript webpack webpack-2 survivejs

我的项目中有一个包含模块和webpack.config的文件夹。

我的webpack.config:

entry: {

    hmr: [
        'webpack-dev-server/client?http://localhost:8080',
        'webpack/hot/only-dev-server'
        // 'webpack/hot/dev-server'
    ],
    app: PATHS.app + '/desktop.js',
    style: PATHS.style

    },
    output: {
        path: PATHS.build,
        publicPath: '/',
        filename: '[name].js',
        sourceMapFilename: '[file].map',
        devtoolModuleFilenameTemplate: 'webpack:///[resource-path]?[loaders]'
    },

    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                exclude: '/node_modules/',
                use: 'eslint-loader',
                enforce: 'pre',
                include: PATHS.app
            },
            {
                test: /\.(js|jsx)$/, 
                exclude: /node_modules/, 
                loader: 'babel-loader',
                options: {
                    presets: ['es2015', 'react' ],
                    cacheDirectory: true 
                }
            },
            {
                test: /\.json$/, 
                loader: "json-loader"
            },
            {
                test: /\.hbs/, 
                loader: "handlebars-template-loader"
            }
        ]
    }, 
    resolve: {
        modules: [
            "node_modules",
            path.resolve(__dirname, "node_modules"),
            path.resolve(__dirname, "../../../../../myModules/"),
        ],
        alias: {
            'react': 'preact-compat',
            'react-dom': 'preact-compat'
        },
        extensions: [".js", ".json", ".jsx", ".css", ".scss", ".hbs"],
    },

我的package.json:

{
  "name": "ETU_ETU",
  "version": "1.0.0",
  "scripts": {
     "start": "nodemon --watch webpack.config.js --exec \"webpack-dev-server --env development\"",
     "build": "webpack --env production",
     "stats": "webpack --env production --profile --json > stats.json",
    "test:lint": "eslint . --ext .js --ext .jsx || true"
  },
  "devDependencies": {
    "babel-core": "^6.21.0",
    "babel-eslint": "^7.1.1",
    "babel-loader": "^6.2.10",
    "babel-plugin-module-resolver": "^2.4.0",
    "babel-plugin-syntax-dynamic-import": "^6.18.0",
    "babel-preset-es2015": "^6.18.0",
    "babel-preset-react": "^6.16.0",
    "babel-preset-stage-0": "^6.16.0",
    "clean-webpack-plugin": "^0.1.14",
    "compression-webpack-plugin": "^0.3.2",
    "css-loader": "^0.26.1",
    "eslint": "^3.12.2",
    "eslint-loader": "^1.6.1",
    "eslint-plugin-react": "^6.8.0",
    "extract-text-webpack-plugin": "^2.0.0-beta.4",
    "friendly-errors-webpack-plugin": "^1.1.2",
    "handlebars-loader": "^1.4.0",
    "handlebars-template-loader": "^0.7.0",
    "html-loader": "^0.4.4",
    "html-webpack-plugin": "^2.24.1",
    "json-loader": "^0.5.4",
    "node-sass": "^4.1.0",
    "npm-install-webpack-plugin": "^4.0.4",
    "purifycss-webpack-plugin": "^2.0.3",
    "required-loader": "^1.1.11",
    "sass-loader": "^4.1.0",
    "style-loader": "^0.13.1",
    "svg-sprite-loader": "^0.1.2",
    "webpack": "^2.2.0-rc.1",
    "webpack-dev-server": "^2.2.0-rc.0",
    "webpack-merge": "^1.1.2",
    "webpack-notifier": "^1.5.0"
  },
  "dependencies": {
    "domready": "^1.0.8",
    "handlebars": "^4.0.6",
    "lodash": "^4.17.2"
  }
}

在我的模块中,我的package.json:

{
  "name": "myModule1",
  "version": "2.0.0",
  "description": "",
  "main": "src/index.js",
  "devDependencies": {
    "cz-conventional-changelog": "^1.2.0"
  },
  "config": {
    "commitizen": {
       "path": "./node_modules/cz-conventional-changelog"
    }
  }
}

在我的desktop.js中,当我导入myModule1时。我有这个错误: 模块构建失败:错误:无法找到预设" es2015"相对于目录" / space / www / myModules / myModule1 / src"

如果我删除es2015预设,我有同样的问题。

所以,我不明白,因为我使用的是resolve.module。

你有解决方案吗?

谢谢,

0 个答案:

没有答案