我是webpack的新手,我试图了解在开发模式下输出中的“ WEBPACK VAR INJECTION”代码是什么。
package.json
{
"name": "tests-webpack",
"version": "1.0.0",
"description": "",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build-dev": "webpack -d --mode development",
"build-prod": "webpack -p --mode production"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.6.2",
"@babel/core": "^7.6.2",
"@babel/preset-env": "^7.6.2",
"babel-loader": "^8.0.6",
"webpack": "^4.41.0",
"webpack-cli": "^3.3.9"
},
"dependencies": {
"lodash": "^4.17.15"
}
}
webpack.config.js
const path = require('path');
module.exports = {
mode: 'development',
entry: './src/app.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'main.js'
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}]
}
};
npm运行build-dev
那是什么?我认为也许可以通过webpack.config中的devtool参数来控制它,但是,那么,这应该是通常的配置吗?
另一个问题>查看我的配置,我是否应该做更多的事情来实现良好的babel转换(对于也应该在IE11中工作的生产项目)?我是否应该在babel专用文件或package.json中的mayb中添加更多babel配置?我有点困惑:)