npx webpack 报错我实在找不出原因
const path = require('path') const nodeExternals = require('webpack-node-externals') const { CleanWebpackPlugin } = require('clean-webpack-plugin') debugger const webpackconfig = { target: 'node', mode: 'development', entry: { server: path.join(__dirname, 'src/index.js') }, output: { filename: '[name].bundle.js', path: path.join(__dirname, './dist') }, devtool: 'eval-source-map', module: { rules: [ { test: /\.(js|jsx)$/, use: { loader: 'babel-loader' }, exclude: [path.join(__dirname, '/node_modules')] } ] }, externals: [nodeExternals()], plugins: [ new CleanWebpackPlugin() ], node: { console: true, global: true, process: true, Buffer: true, __filename: true, __dirname: true, setImmediate: true, path: true } } console.log(webpackconfig) const a = 0 module.exports = webpackconfig
92
收起
正在回答 回答被采纳积分+1
1回答
Brian
2019-12-29 22:31:16
我跟你一样的配置,没有打包出现错误:
package.json
{ "name": "webpack-demo", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "@babel/core": "^7.7.7", "babel-loader": "^8.0.6", "clean-webpack-plugin": "^3.0.0", "webpack": "^4.41.5", "webpack-cli": "^3.3.10", "webpack-node-externals": "^1.7.2" } }
webpack.config.js
const path = require('path') const nodeExternals = require('webpack-node-externals') const { CleanWebpackPlugin } = require('clean-webpack-plugin') const webpackconfig = { target: 'node', mode: 'development', entry: { server: path.join(__dirname, 'src/index.js') }, output: { filename: '[name].bundle.js', path: path.join(__dirname, './dist') }, devtool: 'eval-source-map', module: { rules: [ { test: /\.(js|jsx)$/, use: { loader: 'babel-loader' }, exclude: [path.join(__dirname, '/node_modules')] } ] }, externals: [nodeExternals()], plugins: [ new CleanWebpackPlugin() ], node: { console: true, global: true, process: true, Buffer: true, __filename: true, __dirname: true, setImmediate: true, path: true } } module.exports = webpackconfig
node, nvm版本:
➜ node -v
v12.13.1
➜ nvm --version
0.35.1
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星