前提・実現したいこと
表題の通り、webpack-dev-serverでphpファイルを監視したいのですが、devServerのopenPage
でindex.php
を指定すると、phpファイルがダウンロードされてしまい、参照することが出来ません。
htmlにすると、問題なく参照されます。
phpを参照させる場合、何かほかに記述をしなければいけないとかがあるのでしょうか。
webpack.config.js
const webpack = require('webpack'); const path = require('path'); const ExtractTextWebpackPlugin = require('extract-text-webpack-plugin'); const autoprefixer = require('autoprefixer'); module.exports = { mode: 'development', entry: { './public/assets/application.js': './src/js/index.js', './public/assets/style.css': './src/sass/index.scss' }, output: { path: __dirname, filename: '[name]' }, devServer: { open: true, openPage: 'index.php', contentBase: path.join(__dirname, 'public'), watchContentBase: true, port: 3000, }, devtool: "source-map", module: { rules: [{ test: /.js$/, use: [{ loader: 'babel-loader', options: { presets: 'env' } }], exclude: /node_modules/, }, { test: /.scss$/, use: [ ExtractTextWebpackPlugin.loader, { loader: 'css-loader', options: { url: false, sourceMap: true, minimize: true } }, { loader: 'sass-loader', options: { sourceMap: true } }, { loader: 'postcss-loader', options: { sourceMap: true, plugins: [autoprefixer({ browsers: 'last 2 versions', grid: true })] } } ] }] }, plugins: [new ExtractTextWebpackPlugin('[name]'), ] }
package.json
{ "name": "new-webpack", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "webpack-dev-server" }, "author": "", "license": "ISC", "devDependencies": { "autoprefixer": "^9.3.1", "babel-core": "^6.26.3", "babel-loader": "^7.1.5", "babel-preset-env": "^1.7.0", "css-loader": "^0.28.10", "extract-text-webpack-plugin": "^4.0.0-beta.0", "node-sass": "^4.10.0", "postcss-loader": "^3.0.0", "sass-loader": "^7.1.0", "webpack": "^4.26.0", "webpack-cli": "^3.1.2", "webpack-dev-server": "^3.1.10" }, "dependencies": {} }

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。