-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webpack那些事儿 #130
Comments
webpack 常用命令
|
webpack 疑问汇总
webpack解析里的扩展配置:
resolve: {
extensions: ['.wasm', '.js', '.vue', '.json']
} 详细资料可以看这里:https://webpack.js.org/configuration/resolve/#resolveextensions
在拥有eslint-loader,vue-loader,babel-loader的情况下,一般来说会指定eslint-loader的enforce值为pre,确保首先验证.eslintrc.js中的eslint规则,通过验证再走后续的vue-loader和babel-loader。 引申问题:pitching是什么?
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000, // 小于10KB url-loader生效直接将文件转换成base64url;大于10KB通过file-loader加载到项目文件中。
name: utils.assetsPath('img/[name].[hash:7].[ext]'), /* 这是file-loader的文件名,由[path]/[name].[hash:7].[ext]组成。path是相对webpack/config context的目录。name是file.basename。[<hashType>:hash:<digestType>:<length>]
。加密类型有md5, sha1, sha256, and sha512。编码类型:base26, base32, base36, base49, base52, base58, base62, base64, and hex.length是哈希值的长度。ext是file.extname。 https://webpack.js.org/loaders/file-loader/#path */
},
}, url-loader源码明确告诉我们url-loader limit的作用原理: if(!limit || content.length < limit) {
if(typeof content === "string") {
content = new Buffer(content);
}
return "module.exports = " + JSON.stringify("data:" + (mimetype ? mimetype + ";" : "") + "base64," + content.toString("base64"));
}
var fileLoader = require("file-loader");
return fileLoader.call(this, content);
}
// foo.js
module.exports = {
a: 1,
b: [1]
}
// bar.js
module.exports = {
a: 2,
b: [2],
}
// webpack-merge-test.js
const merge = require('webpack-merge');
const foo = require('./foo');
const bar = require('./bar');
console.log(merge(foo, bar)); 输出:
默认关闭,因为开启后会增加运行时开销并增大包的大小。 那么开发环境开启与不开启的区别是什么呢?
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, '../static'),
to: config.dev.assetsSubDirectory,
ignore: ['.*'],
},
]), 复制static到static。
|
ExtractTextPlugin是抽离css的吧 |
是的,2年前的理解有误。 已经改过来了 |
The text was updated successfully, but these errors were encountered: