npm run watch 不会在特定更改时重新加载
Posted
技术标签:
【中文标题】npm run watch 不会在特定更改时重新加载【英文标题】:npm run watch does not reload on specific changes 【发布时间】:2020-04-02 12:26:16 【问题描述】:我想在更改某些内容后使用npm run watch
重建我的资产。
这对几乎所有文件都适用,但对于我添加到 pages
目录的文件不。如果我在更改pages
-dir 后再次运行npm run watch
,则正在处理更改。
这是我的树:
.
├── App.vue
├── components
│ └── Cards
│ └── Video.vue
├── entry-point.js
├── layouts
│ └── Layout1.vue
├── main.js
├── pages
│ └── Home
│ └── View.vue
├── router
│ ├── errors.js
│ ├── home.js
│ └── index.js
└── stores
这是App.vue
:
<template>
<router-view/>
</template>
<script>
export default
name: 'app',
</script>
这是main.js
import Vue from 'vue'
import App from './App'
import Routes from '@/js/router/index'
const main = new Vue(
el: '#app',
router: Routes,
render: h => h(App)
);
export default main;
这是router/index.js
:
import Vue from 'vue'
import Router from 'vue-router'
import homeRoutes from './home'
Vue.use (Router);
const ROUTES = [
// Default route
path: '', redirect: '/home'
]
.concat (homeRoutes);
const router = new Router (
base: '/',
mode: 'history',
routes: ROUTES
);
export default router
这是router/home.js
:
import Layout1 from '@/js/layouts/Layout1'
export default [
path: '/home',
component: Layout1,
children: [
path: '/',
component: () => import( /* webpackChunkName: "home-view" */ '@/js/Pages/Home/View'),
]
]
现在我们得到了webpack.mix.js
:
const EnvironmentPlugin = require ('webpack');
const mix = require ('laravel-mix');
const glob = require ('glob');
const path = require ('path');
const CleanWebpackPlugin = require ('clean-webpack-plugin');
const ChunkRenamePlugin = require ('webpack-chunk-rename-plugin');
require ('laravel-mix-tailwind');
require ('laravel-mix-purgecss');
mix.webpackConfig (
output:
chunkFilename: 'js/chunks/[name].[chunkhash].js'
,
plugins: [
new CleanWebpackPlugin (
cleanOnceBeforeBuildPatterns: ['chunks/**/*']
),
new EnvironmentPlugin (
BASE_URL: '/'
),
new ChunkRenamePlugin (
initialChunksWithEntry: true,
'/js/app': 'js/entry-point.js',
'/js/vendor': 'js/vendor.js',
),
],
module:
rules: [
test: /node_modules(?:\/|\\).+\.js$/,
loader: 'babel-loader',
options:
presets: [['@babel/preset-env', targets: 'last 2 versions, ie >= 10']],
plugins: ['@babel/plugin-transform-destructuring', '@babel/plugin-proposal-object-rest-spread', '@babel/plugin-transform-template-literals'],
babelrc: false
,
]
,
resolve:
alias:
'@': path.join (__dirname, 'resources'),
'node_modules': path.join (__dirname, 'node_modules')
,
);
mix.js ('resources/js/entry-point.js', 'public/js')
.postCss ('resources/css/app.css', 'public/css')
.tailwind ('./tailwind.config.js');
if (mix.inProduction ())
mix
.version ()
.purgeCss ();
我认为这是因为我的 webpack.mix.js
中缺少配置,但我无法弄清楚如何解决这个问题。
【问题讨论】:
pages
目录的路径是什么?
【参考方案1】:
解决方案很简单:Pages
目录在文件结构中是小写的,但在我的路由器定义中是大写的。
【讨论】:
以上是关于npm run watch 不会在特定更改时重新加载的主要内容,如果未能解决你的问题,请参考以下文章
当页面重新加载时正在监视的属性未更改时,Vue watch 不会运行
Laravel npm run watch 不能在运行时 scss 和 js 中编译