我已经按照 webpack4 示例来设置配置:https ://github.com/serverless-heaven/serverless-webpack/tree/master/examples/babel-webpack-4 因为我收到错误“找不到模块源-地图支持/注册”。
我已经调查了已经创建的问题:
https://github.com/serverless-heaven/serverless-webpack/issues/357
https://github.com/serverless-heaven/serverless-webpack/issues/228
现在我的配置是:
.babelrc{
"comments": false,
"sourceMaps": "both",
"presets": ["env","stage-2"],
"plugins": ["source-map-support"]
}
webpack.config.js:
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const slsw = require('serverless-webpack');
module.exports = {
entry: slsw.lib.entries,
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
output: {
libraryTarget: 'commonjs2',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
sourceMapFilename: '[file].map',
},
optimization: {
// We no not want to minimize our code.
minimize: false,
},
performance: {
// Turn off size warnings for entry points
hints: false,
},
target: 'node',
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
include: [path.join(__dirname, 'src')],
exclude: /node_modules/,
},
{
test: /\.json$/,
loader: 'json',
include: path.join(__dirname, 'src'),
},
],
},
externals: [nodeExternals()],
devtool: 'source-map',
};
包.json
{
"name": "someservice",
"version": "2.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest --config --colors",
"lint": "eslint . --max-warnings=0 --report-unused-disable-directives && echo '✔ Your .js files look good.'"
},
"author": "abc@gmail.com",
"license": "ISC",
"devDependencies": {
"babel": "^6.23.0",
"babel-core": "^6.26.3",
"babel-jest": "^23.4.2",
"babel-loader": "^7.1.5",
"babel-plugin-source-map-support": "^2.0.1",
"babel-plugin-transform-class-properties": "^6.22.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"babel-plugin-transform-inline-environment-variables": "^6.8.0",
"babel-plugin-transform-object-rest-spread": "^6.22.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-latest": "^6.22.0",
"babel-preset-stage-2": "^6.24.1",
"eslint": "^5.4.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-airbnb-base": "13.1.0",
"eslint-loader": "^2.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jest": "^21.22.0",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.1.0",
"eslint-plugin-security": "^1.4.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^23.5.0",
"jest-transform-stub": "^1.0.0",
"lint-staged": "^7.2.2",
"prettier-eslint": "^8.8.2",
"prettier-eslint-cli": "^4.3.2",
"serverless-jest-plugin": "^0.1.6",
"serverless-offline": "^3.25.11",
"serverless-webpack": "^5.2.0",
"standard": "^12.0.1",
"webpack": "^4.17.3",
"webpack-node-externals": "^1.7.2",
"babel-runtime": "^6.22.0"
},
"dependencies": {
"aws-sdk": "^2.11.0",
"source-map-support": "^0.5.9"
}
}
无服务器.yml
service: someservice
plugins:
- serverless-offline
- serverless-webpack
provider:
name: aws
runtime: nodejs6.10
region: us-east-1
stage: ${env:STAGE}
custom:
webpackConfig: ./webpack.config.js
includeModules: true
functions:
getUser:
handler: src/user/UserHandler.getUser
memory: 512
timeout: 60
events:
- http:
method: get
path: user
cors: true
integration: lambda
createUser:
handler: src/user/UserHandler.createUser
memory: 512
timeout: 60
events:
- http:
method: post
path: user
cors: true
integration: lambda
我仍然面临同样的问题。它适用于 sls invoke local -f。但是当使用sls deploy部署到 aws 时,它会在调用 API Url 时显示错误。
npm 版本:6.4.1
节点版本:v10.10.0
无服务器:1.30.3