javascript - 如何使用 webpack 创建子目录?
问题描述
我正在尝试使用 webpack 将多个 HTML 文件捆绑在不同的目录中,但无法使其正常工作。
文件夹结构为:
app
/25off
**-index.html**
/assets
/fonts
/images
/scripts
-App.js
/styles
**- index.html**
我想将两个 index.html 文件捆绑在一起。一个将是根目录,然后另一个将位于名为“25off”的子目录中
Webpack 配置为:
const currentTask = process.env.npm_lifecycle_event
const HtmlWebpackPlugin = require('html-webpack-plugin')
let cssConfig = {
test:/\.css$/i,
use: ['css-loader?url=false',
{loader: "postcss-loader", options: {postcssOptions: {plugins: postCSSPlugins}}}
]
}
let config = {
entry: './app/assets/scripts/App.js',
plugins: [
new HtmlWebpackPlugin({filename: 'index.html', template: './app/index.html'}),
new HtmlWebpackPlugin({filename: 'index.html', template: './app/25off/index.html'})
],
module: {
rules: [
cssConfig
]
}
}
if(currentTask == 'dev'){
cssConfig.use.unshift('style-loader')
config.output = {
filename: 'bundled.js',
path: path.resolve(__dirname, 'app')
}
config.devServer = {
before: function(app,server){
server._watch('./app/**/*.html')
},
contentBase: path.join(__dirname, 'app'),
hot: true,
port: 3000,
host: '0.0.0.0'
}
config.mode = 'development'
}
这是我的 App.js 文件的配置方式:
import '../fonts/stylesheet.css'
import '../styles/styles.css'
if(module.hot){
module.hot.accept()
}
CSS 正在应用于我的根 index.html 文件,但不是我的 250ff 目录中的那个,因为捆绑似乎不适用于该文件。我尝试了多种设置,但无法使其正常工作。我在哪里错了?
解决方案
推荐阅读
- python - Python Text RPG - 难以处理我的 while 循环和 if 语句
- python - 线程中的Python套接字recv
- python - 如何验证python函数中行代码的输出
- javascript - 使用引导程序 4 选项卡时将活动类存储在本地存储中
- c++ - 创建将一些文本放入 QTextEdit 的插槽时出现问题
- vba - 将字符串格式的月份转换为 Word 宏中的数字
- java - Gson 使用 TypeAdapter 或 Json Deserializer 将数据从错误列表转换为空列表
- scala - 优先级队列中的不同元素
- windows - 自动热键脚本速度和防止垃圾邮件点击
- python - 在 Raspberry Pi 上使用 Telegram 接收并打印一条消息以损坏 USB 打印机