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
Output file does not contain markup. its more like a webpack js file that outputs markup #90
Comments
please read the manual Install and Quick Start.
Please create a small repository with reproducible issue, then I can help you. |
the correct webpack config: const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const FileManagerPlugin = require('filemanager-webpack-plugin');
const HtmlBundlerPlugin = require('html-bundler-webpack-plugin');
class CurrentTimePlugin {
constructor() {
// You can add any options you might want to pass to the plugin here
}
apply(compiler) {
compiler.hooks.done.tap('CurrentTimePlugin', (stats) => {
setTimeout(() => {
const currentTime = new Date().toLocaleString();
console.log('\n\n' + '=========================================================');
console.log('\t' + `Webpack compiled at: ${currentTime}`);
console.log('=========================================================');
}, 100);
});
}
}
module.exports = {
// NOTE: add the source JS file directly in the template using <script src="scripts/app.js"> tag, NOT here
// entry: {
// app: [path.join(__dirname, '../src/js/app.js')],
// },
devServer: {
static: {
directory: path.resolve(__dirname, '../dist'),
serveIndex: true,
watch: true,
},
},
output: {
path: path.resolve(__dirname, '../dist'),
//filename: 'js/[name].js', // <= MOVE into `js.filename` bundler plugin option
},
optimization: {
minimize: false,
minimizer: [
new TerserPlugin({
parallel: true,
}),
new CssMinimizerPlugin(),
],
},
resolve: {
//extensions: ['.js', '.css', '.scss'], // DON'T mix JS and SCSS extensions
extensions: ['.js'],
modules: ['node_modules'],
alias: {
request$: 'xhr',
fonts: path.resolve(__dirname, '../src/fonts'),
components: path.resolve(__dirname, '../src/components'),
modules: path.resolve(__dirname, '../src/modules'),
styles: path.resolve(__dirname, '../src/styles'),
scripts: path.resolve(__dirname, '../src/js'), // <= use alias to define JS in the template
images: path.join(__dirname, '../wp/wp-content/themes/2019-redesign/assets/images'), // <= use alias to define source image files
},
},
module: {
rules: [
{
// babel-loader
test: /\.js$/,
exclude: /node_modules/,
rules: [
{
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
babelrc: false,
rootMode: 'upward',
},
},
],
},
],
},
{
// json loader
test: /\.json$/,
loader: 'json-loader',
},
{
// style loaders
test: /\.(css|sass|scss)$/,
use: [
// MiniCssExtractPlugin.loader, // <= DELETE it
{
loader: 'css-loader',
options: {
sourceMap: true,
importLoaders: 2,
esModule: false,
},
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
},
},
{
loader: 'resolve-url-loader',
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
],
},
{
// Loads fonts
test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
loader: 'url-loader',
options: {
limit: true,
esModule: false,
},
},
{
// Load images
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
generator: {
filename: 'assets/[name][ext]',
},
},
// DELETE the html rule, DON'T use the `html-loader`
// {
// // Allow partials in html pages.
// test: /\.(html)$/,
// // exclude: /node_modules/,
// include: [
// path.resolve(__dirname, '../src/views/partials'),
// path.resolve(__dirname, '../src/components/icon-font/'),
// ],
// use: {
// loader: 'html-loader',
// options: {
// preprocessor: processNestedHtml,
// },
// },
// },
],
},
stats: {
children: true,
},
plugins: [
// NOTE: you can define source image files directly in template using the webpack alias to the image directory,
// then you don't need to copy source images into dist
new FileManagerPlugin({
events: {
onEnd: [
{ delete: ['./dist/images'] },
{
delete: [path.join(__dirname, '../wp/wp-content/themes/2019-redesign/assets/*')],
},
{
copy: [
{
source: path.join(__dirname, '../src/images'),
destination: path.join(__dirname, '../dist/images'),
},
],
},
{
copy: [
{
source: path.join(__dirname, '../dist/images'),
destination: path.join(__dirname, '../wp/wp-content/themes/2019-redesign/assets/images'),
},
],
},
{
copy: [
{
source: path.join(__dirname, '../dist/js'),
destination: path.join(__dirname, '../wp/wp-content/themes/2019-redesign/assets/js'),
},
],
},
{
copy: [
{
source: path.join(__dirname, '../dist/css'),
destination: path.join(__dirname, '../wp/wp-content/themes/2019-redesign/assets/css'),
},
],
},
],
},
}),
// MiniCssExtractPlugin // <= DELETE it
// new MiniCssExtractPlugin({
// filename: isHot ? '[name].css' : 'css/[name].css',
// chunkFilename: '[id].css',
// }),
new ESLintPlugin(),
new CurrentTimePlugin(),
new HtmlBundlerPlugin({
entry: {
article: './src/views/article.html',
},
js: {
filename: 'js/[name].js',
},
css: {
filename: 'css/[name].css',
chunkFilename: 'css/[name].chunk.css',
},
}),
],
}; Please create a repo, then I can help you more. |
Thanks so much for your help. I created this little repo to help me get this working: |
Unfortunately, it can't compile the html page tho.
|
of course is not found. You should load the <link href="@styles/app.scss" rel="stylesheet"> and remove this file from JS.
|
My html output contains webpack js, instead of html markup
webpack config:
article.html:
I would expect the html output to be something like:
Actual output:
it's like it's treating this like a js file.
Environment:
Mac OS
node v16.13.2
webpack.config:
The text was updated successfully, but these errors were encountered: