質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%

Q&A

解決済

1回答

2102閲覧

pug-loaderでpugコンパイル時に</body>手前に自動で追加される<script>を削除したい

退会済みユーザー

退会済みユーザー

総合スコア0

0グッド

0クリップ

投稿2020/08/06 10:30

前提・実現したいこと

webpackで、pug、sass、es6をコンパイルしています。

コンパイルされたhtmlを見てみると、</body>の手前で<script src~~~></script>が自動で追加されます。

これを追加されないようにする方法はありますでしょうか?

pug-loaderのドキュメントを見た限り、そのような設定が見つかりませんでした。

バージョンなど

node.js: 12.18.3

webpackの各モジュールのバージョンはpackage.jsonをご覧ください。

pug-loaderのバージョンを最新にアップデートすると、optionpretty: trueが効かなくなるので、現在のバージョンでどうにかしたいです。

webpack.config.js

const path = require('path'); const globule = require('globule'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); const TerserPlugin = require('terser-webpack-plugin'); const FixStyleOnlyEntriesPlugin = require('webpack-fix-style-only-entries'); const HtmlWebpackPlugin = require('html-webpack-plugin'); // ディレクトリの設定 const dir = { src: path.join(__dirname, '_src'), public: path.join(__dirname, 'public'), assets: 'assets', } const from = 'pug'; const to = 'html'; const htmlPluginConfig = globule.find([`**/*.${from}`, `!**/_*.${from}`], { cwd: dir.src }).map(filename => { const file = filename.replace(new RegExp(`.${from}$`, 'i'), `.${to}`).split('/') return new HtmlWebpackPlugin({ filename: filename.replace(new RegExp(`.${from}$`, 'i'), `.${to}`).replace(/(./)?pug/, '.'), template: `./${filename}`, }) }) module.exports = { context: dir.src, entry: { application: path.resolve(dir.src, 'js/_index.js'), 'style.css': path.resolve(dir.src, 'sass/_index.sass'), }, output: { filename: `${dir.assets}/js/[name].js`, // filename: path.resolve(dir.assets, 'js/[name].js'), path: dir.public, }, plugins: [ new FixStyleOnlyEntriesPlugin(), new MiniCssExtractPlugin({ filename: `${dir.assets}/css/[name]`, }), ...htmlPluginConfig, ], resolve: { modules: ['node_modules'], extensions: ['.js', '.css'], }, devtool: 'source-map', optimization: { minimizer: [ new OptimizeCSSAssetsPlugin(), new TerserPlugin({ terserOptions: { ecma: 6, compress: true, output: { comments: false, beautify: false } } }) ], }, module: { rules: [{ test: /.js$/, exclude: /node_modules/, use: [{ loader: 'babel-loader', options: { presets: [ '@babel/preset-env', ] } }] }, { test: /.(sass|scss|css)$/, use: [{ loader: MiniCssExtractPlugin.loader, }, { loader: 'css-loader', options: { url: false, sourceMap: true, importLoaders: 2 }, }, { loader: 'postcss-loader', options: { sourceMap: true, plugins: [ require('autoprefixer')({ grid: true }) ] } }, { loader: 'sass-loader', options: { sourceMap: true, } }, ], }, { test: /.pug$/, use: { loader: 'pug-loader', options: { pretty: true } } } ] } };

package.json

{ "name": "webpack", "version": "1.0.0", "private": true, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "watch": "webpack --watch --inline --mode=development", "build": "webpack --mode=production" }, "devDependencies": { "@babel/core": "^7.11.0", "@babel/preset-env": "^7.11.0", "autoprefixer": "^9.8.6", "babel-loader": "^8.1.0", "css-loader": "^3.6.0", "globule": "^1.3.2", "html-webpack-plugin": "^4.3.0", "mini-css-extract-plugin": "^0.9.0", "optimize-css-assets-webpack-plugin": "^5.0.3", "postcss-loader": "^3.0.0", "pug": "^2.0.3", "pug-loader": "^2.4.0", "sass": "^1.26.10", "sass-loader": "^9.0.2", "terser-webpack-plugin": "^3.1.0", "webpack": "^4.43.0", "webpack-cli": "^3.3.12", "webpack-fix-style-only-entries": "^0.5.1" }, "browserslist": [ "last 2 version", "> 1%" ] }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

html-webpack-pluginのオプションで解決しました。

投稿2020/08/07 07:55

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問