我进行了Webpack配置,可以在编码过程中编译和监视我的资产-您可以在下面查看。我的问题是,在我的机器(Macbook Pro 2015)上,它运行良好,并且所有内容都已编译,监视并在浏览器中的每次更改重新加载。但是在我的同事机器Macbook Air上,它仅在配置启动时编译所有内容,并且在每次更改时,它只会重新加载浏览器,而不会重新编译资产。你能帮我吗?
Webpack配置:
const path = require("path");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const HtmlCriticalWebpackPlugin = require('html-critical-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const localServer = {
host: 'localhost',
port: 3000
}
module.exports = {
mode: "development",
entry: './src/js/index.ts',
module: {
rules: [{
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/]
}
},
exclude: '/node_modules/'
}, {
test: /\.s?css$/,
exclude: '/node_modules/',
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader'
]
}, {
test: /\.vue/,
use: 'vue-loader'
}, {
test: /\.styl$/,
use: [
'style-loader',
'css-loader',
'postcss-loader',
'stylus-loader'
]
},
{
test: /\.(jpe?g|gif|png|mp3)$/,
use: [
{
loader: 'url-loader',
options: {name: 'img/[folder]/[name].[hash:6].[ext]', publicPath: '../', limit: 8192},
},
],
},
{
test: /\.(eot|otf|svg|ttf|woff|woff2)$/,
use: [
{
loader: 'url-loader',
options: {name: 'fonts/[folder]/[name].[hash:6].[ext]', publicPath: '../', limit: 8192},
},
],
}]
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.vue'],
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
},
output: {
path: path.resolve(__dirname, "../dist"),
filename: "js/scripts.js"
},
plugins: [
new MiniCssExtractPlugin({
filename: 'css/style.css',
chunkFilename: 'css/style.[id].css'
}),
new VueLoaderPlugin(),
new BrowserSyncPlugin({
host: localServer.path,
proxy: localServer.path,
port: localServer.port,
files: ['*.html', 'src/sass/*', 'src/js/*', 'src/fonts/*', 'src/images/*', 'templates/partials/*.*', 'templates/components/*.*'],
ghostMode: {
clicks: false,
location: false,
forms: false,
scroll: false,
},
injectChanges: true,
logFileChanges: true,
logLevel: 'debug',
logPrefix: 'wepback',
notify: true,
reloadDelay: 0
}),
new CopyWebpackPlugin([
{from: 'src/img', to: 'img'},
{from: 'src/fonts', to: 'fonts'}
])
],
watch: true
}
我的package.json:
{
"name": "test",
"version": "0.0.1",
"private": true,
"scripts": {
"build": "webpack --config webpack/config.prod.js",
"lint": "vue-cli-service lint",
"dev": "webpack --open --config webpack/config.dev.js | webpack-dev-server --open --config webpack/config.dev.js"
},
"dependencies": {
"bootstrap-vue": "^2.0.0-rc.11",
"copy-webpack-plugin": "^4.5.1",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.8.2",
"html-critical-webpack-plugin": "^2.0.0",
"html-webpack-plugin": "^3.2.0",
"optimize-css-assets-webpack-plugin": "^4.0.2",
"vue": "^2.5.16",
"vue-resource": "^1.5.1"
},
"devDependencies": {
"@vue/cli-plugin-eslint": "^3.0.0-rc.10",
"@vue/eslint-config-standard": "^3.0.0-rc.10",
"@vue/eslint-config-typescript": "^3.0.0-rc.10",
"autoprefixer": "^8.5.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"browser-sync": "^2.24.6",
"browser-sync-webpack-plugin": "^2.2.2",
"css-loader": "^0.28.11",
"cssnano": "^3.10.0",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"file-loader": "^1.1.11",
"mini-css-extract-plugin": "^0.4.0",
"node-sass": "^4.9.2",
"optimize-css-assets-webpack-plugin": "^4.0.1",
"postcss-loader": "^2.1.5",
"sass-lint": "^1.12.1",
"sass-loader": "^7.0.3",
"script-loader": "^0.7.2",
"style-loader": "^0.21.0",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.2",
"ts-loader": "^4.4.1",
"typescript": "^2.9.2",
"url-loader": "^1.0.1",
"vue-class-component": "^6.2.0",
"vue-loader": "^15.2.4",
"vue-property-decorator": "^6.1.0",
"vue-template-compiler": "^2.5.16",
"vue-template-compiler-loader": "^1.0.4",
"webpack": "^4.12.0",
"webpack-cli": "^3.0.6",
"webpack-dev-server": "^3.1.4",
"webpack-livereload-plugin": "^2.1.1"
},
"homepage": "",
"license": "UNLINCENSED",
"author": {
},
"contributors": [
{
}
]
}