Ali*_*olm 5 webpack html-webpack-plugin
我正在尝试htmlWebpackPlugin.files.css从 Pug 模板访问,但我的构建失败了,因为这是未定义的。
我希望我能够link为每个 css 文件插入一个标签。谁能告诉我为什么我的 pug 模板看不到数据,如自述文件(https://github.com/jantimon/html-webpack-plugin)中所述?
这是我的 webpack.config.js 文件的当前内容:
const path = require('path');
const webpack = require('webpack')
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = env => {
return {
mode: env.mode,
entry: {
vendor: ['jquery', 'jquery-ui', 'jquery-validation', 'js-cookie', 'qtip2'],
bundle: './src/scripts/bundle.js',
global: './src/scripts/global.js',
index: [
'./src/index.js',
'./src/scripts/branch.js'
],
maincss: './src/scss/main.scss',
},
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name]-[hash].js',
chunkFilename: '[name]-[chunkhash].js'
},
devtool: 'inline-source-map',
devServer: {
contentBase: './build'
},
plugins: [
new CleanWebpackPlugin(['build']),
new MiniCssExtractPlugin({
path: 'build/Styles',
filename: '[name]-[hash].css',
chunkFilename: '[name]-[chunkhash].css'
}),
new HtmlWebpackPlugin({
inject: false,
title: "Home Page",
filename: "home.html",
chunks: ['vendor', 'bundle'],
template: './src/templates/home.html'
}),
new HtmlWebpackPlugin({
inject: false,
title: "Branch Page",
filename: "branch.html",
chunks: ['vendor', 'bundle', 'branch'],
template: './src/templates/branch.html'
}),
new HtmlWebpackPlugin({
// inject: false,
filename: 'basket.html',
template: 'src/basket.pug',
chunks: ['vendor', 'bundle', 'maincss']
})
],
module: {
rules: [
{
test: /\.scss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
name: 'Styles/[name]-[hash].css',
}
},
{
loader: 'css-loader'
},
{
loader: 'sass-loader'
}
]
},
{
test: /\.pug$/,
use: ['html-loader?attrs=false', 'pug-html-loader']
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是导致构建错误的 layout.pug 文件:
doctype html
html
head
title I'm a title
each css in htmlWebpackPlugin.files.css
link(href=css rel="stylesheet")
body
block header
include includes/header
block content
block footer
include includes/footer
each js in htmlWebpackPlugin.files.js
script(src=js)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1633 次 |
| 最近记录: |