前提・実現したいこと
webpackのdevServerを使って作業をしたいのですが、サーバー起動時(webpack-dev-server --inline --config webpack.dev.js
で起動)にjsを編集しても変更が反映されなくて困ってます。
webpackでエラーメッセージは出ておらず、Chrome上では指定された関数が無いと言われています。
しかし、その無いと言われた関数自体の記述をどこにもしていないので、エラーになるはずがありません。
強いて言えば、一番最初にその関数を書いており、ファイル名のミスでエラーに一度なりました。
その時のデータがキャッシュかなんかでChromeに残ってしまい、その後いくらjsを編集しても反映されないのかなと思っています。
webpack.dev.js
const merge = require('webpack-merge') const common = require('./webpack.common.js') const path = require('path') module.exports = merge(common, { mode: 'development', devServer: { open: true, openPage: 'index.html', contentBase: path.join(__dirname, './public/'), watchContentBase: true, port: 3000, }, devtool: 'source-map', })
webpack.common.js
const webpack = require('webpack') const ExtractTextPlugin = require('extract-text-webpack-plugin') const autoprefixer = require('autoprefixer') module.exports = { entry: { './public/application.js': './_src/js/_index.js', './public/style.css': './_src/sass/index.sass', }, output: { path: __dirname, filename: '[name]' }, module: { rules: [ { test: /.js$/, use: [{ loader: 'babel-loader', options: { presets: 'env' } }], exclude: /node_modules/, }, { test: /.sass$/, use: [ ExtractTextPlugin.loader, { loader: 'css-loader', options: { url: false, sourceMap: true, minimize: true } }, { loader: 'postcss-loader', options: { sourceMap: true, plugins: [ autoprefixer({ browsers: 'last 2 versions', grid: true }) ] } }, { loader: 'sass-loader', options: { sourceMap: true } }, ] } ] }, plugins: [ new ExtractTextPlugin('[name]'), ] }
ディレクトリ階層
|--_src | |--js | | |--_index.js | | |--hello.js | |--sass | | |--.DS_Store | | |--index.sass |--package.json |--public | |--application.js | |--application.js.map | |--index.html | |--style.css | |--style.css.map |--webpack.common.js |--webpack.dev.js |--webpack.prod.js
バージョン
"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", "file-loader": "^2.0.0", "jquery": "^1.9.1", "node-sass": "^4.10.0", "postcss-loader": "^3.0.0", "sass-loader": "^7.1.0", "style-loader": "^0.23.1", "webpack": "^4.26.0", "webpack-cli": "^3.1.2", "webpack-dev-server": "^3.1.14", "webpack-merge": "^4.1.4"
回答1件
あなたの回答
tips
プレビュー