Comments (2)
在html 模板中自动引入打包文件
通常使用 webpack 打包的项目,会使用 HtmlWebpackPlugin 在模板中自动插入 script 标签,引入打包文件(script 脚本引入的路径是 output 中的 publicPath)。
new HtmlWebpackPlugin({
title: 'test',
template: '!!raw-loader!' + '/template.html', // 模板文件路径
filename: './server/views/index.ejs', // 生成的文件路径,供 node serve
inject: 'body',
hash: false,
minify: {
removeComments: false,
collapseWhitespace: false,
},
}),
from cheungseol.github.io.
在html 模板中自动引入 dll 打包文件
有时候,会将 dll 文件放在 cdn 上,并给 dll 包名以hash值区分。为了在 html 模板文件中自动引入 dll 包文件,需要 AddAssetHtmlPlugin。
webpack.config.js
new AddAssetHtmlPlugin({
includeSourcemap: false,
filepath: path.resolve(__dirname, 'server/static/js/lib.*.js'), // * 符号匹配 dll 哈希名称
}),
webpack 编译时提示 ”...dll.js.map not found“, 需要配置插件选项:includeSourcemap: false,
。
dll.config.js
module.exports = {
entry: {
lib: ['react', 'react-dom', 'react-router-dom', 'react-router-redux', 'react-router-config', 'react-redux'],
},
output: {
path: path.resolve(__dirname, 'server/public/js'),
filename: '[name].[hash:8].js', // 生成的 dll 文件以hash命名
library: '[name]',
},
plugins: [
new webpack.DllPlugin({
path: './manifest.json',
name: '[name]',
context: path.resolve(__dirname, 'client/'),
}),
],
cache: true,
};
参考
devtool: 'eval' causes vendor.dll.js.map error #13
from cheungseol.github.io.
Related Issues (20)
- Webpack in Action (2) HOT 1
- Webpack in Action (3)
- [Node]-util.promisify
- [Node] 错误优先回调
- [React] version 16 Error Handling
- Webpack in Action (4)
- 脚本ssh登录
- [Git]删除所有不在远程仓库维护的分支
- [WebGL] (1)
- callback && promise && async/await
- [React] React Hooks 中使用 setTimeout HOT 1
- Protobuf.js 解析 int64
- AbortController 使用总结
- CommonJS、CMD、AMD 模块规范
- 使用 dataloader 优化 GraphQL 性能
- Deno 实战
- 相交检测
- 浏览器重绘重排
- 《代码精进之路 从码农到工匠》
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cheungseol.github.io.