After I npm run build
generate the dist files, I run the index.html
, all the resources files can not load:
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (main.1f51eed1059b282ae3ed.css, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (main.1f51eed1059b282ae3ed.js, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (vendors.1f51eed1059b282ae3ed.js, line 0)
[Error] Did not load script at 'http://localhost:63342/dist/vendors.1f51eed1059b282ae3ed.js' because non script MIME types are not allowed when 'X-Content-Type: nosniff' is given.
[Error] Did not load script at 'http://localhost:63342/dist/main.1f51eed1059b282ae3ed.js' because non script MIME types are not allowed when 'X-Content-Type: nosniff' is given.
My dist files:
my webpack.base.config.js
:
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: {
main: './src/main',
vendors: './src/vendors'
},
output: {
path: path.join(__dirname, './dist')
},
module: {
rules: [
{
test: /.vue$/,
use: [{
loader: 'vue-loader',
options: {
loaders: {
less: ExtractTextPlugin.extract({
use: ['css-loader?minimize', 'autoprefixer-loader', 'less-loader'],
fallback: 'vue-style-loader'
}),
css: ExtractTextPlugin.extract({
use: ['css-loader', 'autoprefixer-loader', 'less-loader'],
fallback: 'vue-style-loader'
})
}
}
},
{
loader: 'iview-loader',
options: {
prefix: false
}
}
]
},
{
test: /iview\/.*?js$/,
loader: 'babel-loader'
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
use: ['css-loader?minimize', 'autoprefixer-loader'],
fallback: 'style-loader'
})
},
{
test: /\.less$/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "less-loader" // compiles Less to CSS
}]
},
{
test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/,
loader: 'url-loader?limit=1024'
},
{
test: /\.(html|tpl)$/,
loader: 'html-loader'
}
]
},
resolve: {
extensions: ['.js', '.vue'],
alias: {
'vue': 'vue/dist/vue.esm.js',
'@': path.resolve('src')
}
}
};
my webpack.prod.config.js
:
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const merge = require('webpack-merge');
const webpackBaseConfig = require('./webpack.base.config.js');
const fs = require('fs');
fs.open('./src/config/env.js', 'w', function (err, fd) {
const buf = 'export default "production";';
fs.write(fd, buf, 0, buf.length, 0, function (err, written, buffer) {
});
});
module.exports = merge(webpackBaseConfig, {
output: {
publicPath: '/dist/',
filename: '[name].[hash].js',
chunkFilename: '[name].[hash].chunk.js'
},
plugins: [
new ExtractTextPlugin({
filename: '[name].[hash].css',
allChunks: true
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendors',
filename: 'vendors.[hash].js'
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new HtmlWebpackPlugin({
filename: './index.html',
template: './src/template/index.ejs',
inject: false
})
]
});
I am not sure whether is caused by the configuration, who can tell me why I can not load the dist files when I run the dist index.html
in browser?
the url in the browser:
http://localhost:63342/wx_backup/dist/index.html?_ijt=gutju68tikagu6rldhshoenmrv
I also tried:
http://localhost:63342/wx_backup/dist/index.html
If you've just placed an index. html or index. php file on your server's document root folder, for example: /public_html/ and you're still not getting it to load these files upon a request to your domain, chances are your server is missing a specific configuration for the "DirectoryIndex Directive".
I guess you created this project via vue-cli, you might not noticed there was a tip after you completed npm run build command.
Tip: built files are meant to be served over an HTTP server. Opening index.html over file:// won't work.
So for developing, just need to use npm run dev or npm run start to debug and hot reload.
As for production release, you'd better put the dist files to a static file server such as Nginx, Apach, IIS or even hosted via express static file middleware.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With