![](/img/trans.png)
[英]In the webpack-simple Vue.js template, how can I access the Vue app from the console?
[英]How do I deploy Vue Webpack-simple app to Netlify?
這是我第一次嘗試使用webpack-simple模板。 我對webpack的總體經驗很少,我希望有人可以幫助我指出正確的方向。 我正在嘗試部署一個使用webpack-simple到Netlify的Vue應用程序。
我的理解是,我應該能夠在Netlify上運行npm run build
或yarn build
,並且瞧......但是,我在部署之后得到了404。 以下是應該影響Netlify部署的文件:
這是我的webpack配置:
var path = require('path')
var webpack = require('webpack')
require("babel-polyfill");
module.exports = {
entry: ["babel-polyfill", './src/main.js'],
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
filename: 'build.js'
},
module: {
rules: [
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
],
}, {
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
}
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
},
{
test: /\.(woff|woff2)(\?.*$|$)/,
loader: 'url-loader?importLoaders=1&limit=100000'
},
{
test: /\.svg$/,
loader: 'vue-svg-loader',
},
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
},
extensions: ['*', '.js', '.vue', '.json']
},
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true
},
performance: {
hints: false
},
devtool: '#eval-source-map'
}
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
}
還有我的package.json。 我擁有依賴項中的所有內容而不是devDependencies,但Netlify有時會為我的dev依賴項扼殺。
{
"name": "quotes",
"description": "blah blah blah",
"version": "1.0.0",
"author": "Me",
"license": "MIT",
"private": true,
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
},
"dependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-regenerator": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.0",
"babel-preset-stage-3": "^6.24.1",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"cross-env": "^5.0.5",
"css-loader": "^0.28.7",
"file-loader": "^1.1.4",
"html-loader": "^0.5.5",
"prettier": "^1.12.1",
"url-loader": "^1.1.1",
"vue": "^2.5.11",
"vue-loader": "^13.0.5",
"vue-router": "^3.0.1",
"vue-svg-loader": "^0.10.0",
"vue-template-compiler": "^2.4.4",
"vuelidate": "^0.7.4",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.9.1"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
我的vue.config
module.exports = {
baseUrl: '/'
}
最后,我的babel.rc
{
"presets": [
["env", { "modules": false }],
"stage-3"
],
"plugins": [
"syntax-dynamic-import",
"transform-regenerator"
]
}
部署日志中沒有錯誤。 Netlify建議部署該站點。 但是,我一直收到“找不到頁面”的錯誤。 我懷疑我在這里缺少一些簡單的東西。
此外,當我在本地開發環境中運行構建時,我在dist文件夾中只看到兩個文件。 它們是build.js和build.js.map文件。 我是否還應該在某處看到一個html文件? 任何幫助表示贊賞。 謝謝。
Vue webpack-simple
模板不會創建完成的構建文件夾。 它假設您將從項目的根目錄托管您的站點。
這個例子有幾個簡單的選項可以在Netlify上托管:
項目中的任何內容都將部署到Netlify CDN。 最佳實踐是避免這種解決方案,但這只是一個例子,所以我們將證明它是可能的。 它有助於我們了解Netlify的工作原理。
將以下netlify.toml
添加到項目的根目錄中
netlify.toml
[build]
command = "yarn build"
publish = "/"
這將要求您確保添加到站點的任何資產也會復制到構建文件夾。
將以下netlify.toml
添加到項目的根目錄中
netlify.toml
[build]
command = "yarn build && mkdir build && cp index.html build && cp -r dist build/dist"
publish = "build"
還要將build/
添加到.gitignore
文件中。
注意:復制命令可以移動到package.json
的腳本部分。 以上適用於這個簡單的工作示例。 此外,在更高級的webpack解決方案中, dist
文件夾將是您的部署文件夾,並將為您處理index.html
的副本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.