Reputation: 198
I'd like to use npm run watch
to rebuild my assets once I changed something.
This works fine for almost all files, but not for files I added to the pages
dir. If I run npm run watch
again after a change in pages
-dir, the change is being processed.
This is my tree:
.
├── 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
This is App.vue
:
<template>
<router-view/>
</template>
<script>
export default {
name: 'app',
}
</script>
This is 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;
This is 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
This is 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'),
}]
}]
And now we got the 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 ();
}
I assume this happens because a lack of config in my webpack.mix.js
but I was not able to figure out how to solve this issue.
Upvotes: 2
Views: 2865
Reputation: 198
The solution was simple: The Pages
directory is lowercase in the file structure, but uppercase in my router's definition.
Upvotes: 8