admin管理员组文章数量:1296310
Note: I'm a beginner to webpack.
I'm trying to get webpack to load my .htmls files (index.html and login.html) as they will serve as windows for my electron application. This is what I have tried so far with no results:
rules: [
{
test: /\.html$/,
use: ["html-loader"]
},
...
and
rules: [
{
test: /\.html$/,
loader: "file-loader"
},
...
This is my webpack.config.js file:
const path = require("path");
const { spawn } = require("child_process");
const srcDir = path.resolve(__dirname, "src/renderer");
const outDir = path.resolve(__dirname, "build/client");
const defaultIncludes = [srcDir];
module.exports = {
entry: `${srcDir}/index`,
output: {
path: outDir,
filename: "app.bundle.js"
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".json", ".html"]
},
module: {
rules: [
{
test: /\.html$/,
loader: "file-loader"
},
{
// Include ts, tsx, and js files.
test: /\.(tsx?)|(js)$/,
exclude: /node_modules/,
loader: "babel-loader",
include: defaultIncludes
},
{
test: /\.scss$/,
use: [
"style-loader", // creates style nodes from JS strings
"css-loader", // translates CSS into CommonJS
"sass-loader" // piles Sass to CSS
]
},
{
test: /\.(ttf|eot|woff|woff2)$/,
loader: "file-loader",
options: {
name: "fonts/[name].[ext]"
}
}
]
},
devServer: {
inline: true,
contentBase: outDir,
press: true,
stats: {
colors: true,
chunks: false,
children: false
},
before() {
spawn("electron", ["."], {
shell: true,
env: process.env,
stdio: "inherit"
}).on("close", code => process.exit(0)).on("error", spawnError => console.error(spawnError));
}
},
target: "electron-renderer",
mode: "development"
};
What am I doing wrong? Webpack builds everything into the /build
yet the .html files (index.html and login.html, which are under my /src/
directory) are not included.
Note: I'm a beginner to webpack.
I'm trying to get webpack to load my .htmls files (index.html and login.html) as they will serve as windows for my electron application. This is what I have tried so far with no results:
rules: [
{
test: /\.html$/,
use: ["html-loader"]
},
...
and
rules: [
{
test: /\.html$/,
loader: "file-loader"
},
...
This is my webpack.config.js file:
const path = require("path");
const { spawn } = require("child_process");
const srcDir = path.resolve(__dirname, "src/renderer");
const outDir = path.resolve(__dirname, "build/client");
const defaultIncludes = [srcDir];
module.exports = {
entry: `${srcDir}/index`,
output: {
path: outDir,
filename: "app.bundle.js"
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".json", ".html"]
},
module: {
rules: [
{
test: /\.html$/,
loader: "file-loader"
},
{
// Include ts, tsx, and js files.
test: /\.(tsx?)|(js)$/,
exclude: /node_modules/,
loader: "babel-loader",
include: defaultIncludes
},
{
test: /\.scss$/,
use: [
"style-loader", // creates style nodes from JS strings
"css-loader", // translates CSS into CommonJS
"sass-loader" // piles Sass to CSS
]
},
{
test: /\.(ttf|eot|woff|woff2)$/,
loader: "file-loader",
options: {
name: "fonts/[name].[ext]"
}
}
]
},
devServer: {
inline: true,
contentBase: outDir,
press: true,
stats: {
colors: true,
chunks: false,
children: false
},
before() {
spawn("electron", ["."], {
shell: true,
env: process.env,
stdio: "inherit"
}).on("close", code => process.exit(0)).on("error", spawnError => console.error(spawnError));
}
},
target: "electron-renderer",
mode: "development"
};
What am I doing wrong? Webpack builds everything into the /build
yet the .html files (index.html and login.html, which are under my /src/
directory) are not included.
1 Answer
Reset to default 7The loader configuration for HTML files will allow require
calls with HTML files to work inside javascript files. With the file loader you'll get a file path and with the HTML loader you'll get the HTML content as a result of the call.
If you want your HTML files to be copied alongside with your piled sources you'll have to use a plugin like copy-webpack-plugin or html-webpack-plugin.
本文标签: javascriptget webpack to include html filesStack Overflow
版权声明:本文标题:javascript - get webpack to include html files - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741635021a2389591.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论