`\r\n }),\r\n // split vendor js into its own file\r\n new webpack.optimize.CommonsChunkPlugin({\r\n name: 'vendor',\r\n minChunks: function (module, count) {\r\n // any required modules inside node_modules are extracted to vendor\r\n return (\r\n module.resource &&\r\n /.js$/.test(module.resource) &&\r\n module.resource.indexOf(\r\n path.join(__dirname, '../node_modules')\r\n ) === 0\r\n )\r\n }\r\n }),\r\n // extract webpack runtime and module manifest to its own file in order to\r\n // prevent vendor hash from being updated whenever app bundle is updated\r\n new webpack.optimize.CommonsChunkPlugin({\r\n name: 'manifest',\r\n chunks: ['vendor']\r\n }),\r\n // copy custom static assets\r\n new CopyWebpackPlugin([\r\n {\r\n from: path.resolve(__dirname, '../static'),\r\n to: config.build.assetsSubDirectory,\r\n ignore: ['.*']\r\n }\r\n ]),\r\n // service worker caching\r\n // new SWPrecacheWebpackPlugin({\r\n // cacheId: 'test',\r\n // filename: 'service-worker.js',\r\n // staticFileGlobs: ['dist/**/*.{js,html,css}'],\r\n // minify: true,\r\n // stripPrefix: 'dist/'\r\n // })\r\n new workboxPlugin.GenerateSW({\r\n cacheId: 'test',\r\n globDirectory: config.build.assetsRoot,\r\n globPatterns: ['**/*.{html,js,css}'],\r\n swDest: path.join(config.build.assetsRoot, 'service-worker.js'),\r\n skipWaiting: false,\r\n clientsClaim: true,\r\n runtimeCaching: [\r\n {\r\n // APIのキャッシュ\r\n urlPattern: /.*api.*/,\r\n handler: 'networkFirst',\r\n options: {\r\n cacheName: 'api',\r\n expiration: {\r\n maxAgeSeconds: 60 * 60 * 24\r\n }\r\n }\r\n }\r\n ]\r\n })\r\n ]\r\n})\r\n\r\nif (config.build.productionGzip) {\r\n const CompressionWebpackPlugin = require('compression-webpack-plugin')\r\n\r\n webpackConfig.plugins.push(\r\n new CompressionWebpackPlugin({\r\n asset: '[path].gz[query]',\r\n algorithm: 'gzip',\r\n test: new RegExp(\r\n '\\.(' +\r\n config.build.productionGzipExtensions.join('|') +\r\n ')$'\r\n ),\r\n threshold: 10240,\r\n minRatio: 0.8\r\n })\r\n )\r\n}\r\n\r\nif (config.build.bundleAnalyzerReport) {\r\n const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin\r\n webpackConfig.plugins.push(new BundleAnalyzerPlugin())\r\n}\r\n\r\nmodule.exports = webpackConfig\r\n\r\n```\r\n\r\n\r\n・config/index.js\r\n```javascript\r\n'use strict'\r\n\r\n// see http://vuejs-templates.github.io/webpack for documentation.\r\nconst path = require('path')\r\n\r\nmodule.exports = {\r\n build: {\r\n env: require('./prod.env'),\r\n // index: path.resolve(__dirname, '../dist/index.html'),\r\n // assetsRoot: path.resolve(__dirname, '../dist'),\r\n index: path.resolve(__dirname, '../docs/index.html'),\r\n assetsRoot: path.resolve(__dirname, '../docs'),\r\n assetsSubDirectory: 'static',\r\n // assetsPublicPath: '/',\r\n assetsPublicPath: './',\r\n productionSourceMap: true,\r\n // Gzip off by default as many popular static hosts such as\r\n // Surge or Netlify already gzip all static assets for you.\r\n // Before setting to `true`, make sure to:\r\n // npm install --save-dev compression-webpack-plugin\r\n productionGzip: false,\r\n productionGzipExtensions: ['js', 'css'],\r\n // Run the build command with an extra argument to\r\n // View the bundle analyzer report after build finishes:\r\n // `npm run build --report`\r\n // Set to `true` or `false` to always turn it on or off\r\n bundleAnalyzerReport: process.env.npm_config_report\r\n },\r\n dev: {\r\n env: require('./dev.env'),\r\n port: 8080,\r\n autoOpenBrowser: true,\r\n assetsSubDirectory: 'static',\r\n assetsPublicPath: '/',\r\n proxyTable: {},\r\n // CSS Sourcemaps off by default because relative paths are \"buggy\"\r\n // with this option, according to the CSS-Loader README\r\n // (https://github.com/webpack/css-loader#sourcemaps)\r\n // In our experience, they generally work as expected,\r\n // just be aware of this issue when enabling this option.\r\n cssSourceMap: false\r\n }\r\n}\r\n\r\n```\r\n\r\nお手数ですが、考えられる問題点やVueCLI導入時の留意点などをご教示していただきたいです。\r\nまた、コードの変更以外にも途中でプロジェクト名(フォルダとプロジェクト名がかかれた実装部)を手動で変更した経緯があります。\r\n\r\n宜しくお願い致します。","answerCount":1,"upvoteCount":0,"datePublished":"2018-04-11T10:26:58.882Z","dateModified":"2018-04-11T10:28:38.444Z","acceptedAnswer":{"@type":"Answer","text":"レイアウトを一式変更したところ解消されました。","dateModified":"2018-04-14T08:13:25.547Z","datePublished":"2018-04-14T08:13:25.547Z","upvoteCount":0,"url":"https://teratail.com/questions/121400#reply-185486"},"suggestedAnswer":[],"breadcrumb":{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"トップ","url":"https://teratail.com"},{"@type":"ListItem","position":2,"name":"Vue.jsに関する質問","url":"https://teratail.com/tags/Vue.js"},{"@type":"ListItem","position":3,"name":"Vue.js","url":"https://teratail.com/tags/Vue.js"}]}}}
質問するログイン新規登録
Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

Q&A

解決済

1回答

551閲覧

VueCLI PWA で ?# のURLへ飛ばされる

street

総合スコア34

Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

0グッド

0クリップ

投稿2018/04/11 10:26

編集2018/04/11 10:28

0

0

主題の件、VueCLI PWAでカンタンなTodoアプリを作りました。
ローカルサーバー、ウェブサーバー上でページが正常に開かれるのですが配置されたボタンを押すと ?# が付与されたurlへ飛ばれてしまいます。

■ 現象
http://127.0.0.1:8887/#/に配置されたボタンを押すと、http://127.0.0.1:8887/?#/に飛ばされる。
http://127.0.0.1:8887/?#/上ではボタン等は正常に動作する。

■ 解決したいこと
http://127.0.0.1:8887/?#/に飛ばないようにしたい。
http://127.0.0.1:8887/#/上でボタン等を正常に動作させたい)

以下のサイトを参考にvue-cli pwaをnpm経由でインストール及び実装をしました。
https://qiita.com/gyarasu/items/2f18edc4ae251180d89e

・ライブラリ導入時に実施したこと(npm)
npm uninstall sw-precache-webpack-plugin
npm install --save-dev workbox-webpack-plugin
npm install sass-loader node-sass --save-dev

導入時に変更したコードを抜粋します。

・build/webpack.prod.conf.js

javascript

1'use strict' 2 3const fs = require('fs') 4const path = require('path') 5const utils = require('./utils') 6const webpack = require('webpack') 7const config = require('../config') 8const merge = require('webpack-merge') 9const baseWebpackConfig = require('./webpack.base.conf') 10const CopyWebpackPlugin = require('copy-webpack-plugin') 11const HtmlWebpackPlugin = require('html-webpack-plugin') 12const ExtractTextPlugin = require('extract-text-webpack-plugin') 13const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') 14// const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin') 15const workboxPlugin = require('workbox-webpack-plugin') 16const loadMinified = require('./load-minified') 17 18const env = process.env.NODE_ENV === 'testing' 19 ? require('../config/test.env') 20 : config.build.env 21 22const webpackConfig = merge(baseWebpackConfig, { 23 module: { 24 rules: utils.styleLoaders({ 25 sourceMap: config.build.productionSourceMap, 26 extract: true 27 }) 28 }, 29 devtool: config.build.productionSourceMap ? '#source-map' : false, 30 output: { 31 path: config.build.assetsRoot, 32 filename: utils.assetsPath('js/[name].[chunkhash].js'), 33 chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 34 }, 35 plugins: [ 36 // http://vuejs.github.io/vue-loader/en/workflow/production.html 37 new webpack.DefinePlugin({ 38 'process.env': env 39 }), 40 new webpack.optimize.UglifyJsPlugin({ 41 compress: { 42 warnings: false 43 }, 44 sourceMap: true 45 }), 46 // extract css into its own file 47 new ExtractTextPlugin({ 48 filename: utils.assetsPath('css/[name].[contenthash].css') 49 }), 50 // Compress extracted CSS. We are using this plugin so that possible 51 // duplicated CSS from different components can be deduped. 52 new OptimizeCSSPlugin({ 53 cssProcessorOptions: { 54 safe: true 55 } 56 }), 57 // generate dist index.html with correct asset hash for caching. 58 // you can customize output by editing /index.html 59 // see https://github.com/ampedandwired/html-webpack-plugin 60 new HtmlWebpackPlugin({ 61 filename: process.env.NODE_ENV === 'testing' 62 ? 'index.html' 63 : config.build.index, 64 template: 'index.html', 65 inject: true, 66 minify: { 67 removeComments: true, 68 collapseWhitespace: true, 69 removeAttributeQuotes: true 70 // more options: 71 // https://github.com/kangax/html-minifier#options-quick-reference 72 }, 73 // necessary to consistently work with multiple chunks via CommonsChunkPlugin 74 chunksSortMode: 'dependency', 75 serviceWorkerLoader: `<script>${loadMinified(path.join(__dirname, 76 './service-worker-prod.js'))}</script>` 77 }), 78 // split vendor js into its own file 79 new webpack.optimize.CommonsChunkPlugin({ 80 name: 'vendor', 81 minChunks: function (module, count) { 82 // any required modules inside node_modules are extracted to vendor 83 return ( 84 module.resource && 85 /.js$/.test(module.resource) && 86 module.resource.indexOf( 87 path.join(__dirname, '../node_modules') 88 ) === 0 89 ) 90 } 91 }), 92 // extract webpack runtime and module manifest to its own file in order to 93 // prevent vendor hash from being updated whenever app bundle is updated 94 new webpack.optimize.CommonsChunkPlugin({ 95 name: 'manifest', 96 chunks: ['vendor'] 97 }), 98 // copy custom static assets 99 new CopyWebpackPlugin([ 100 { 101 from: path.resolve(__dirname, '../static'), 102 to: config.build.assetsSubDirectory, 103 ignore: ['.*'] 104 } 105 ]), 106 // service worker caching 107 // new SWPrecacheWebpackPlugin({ 108 // cacheId: 'test', 109 // filename: 'service-worker.js', 110 // staticFileGlobs: ['dist/**/*.{js,html,css}'], 111 // minify: true, 112 // stripPrefix: 'dist/' 113 // }) 114 new workboxPlugin.GenerateSW({ 115 cacheId: 'test', 116 globDirectory: config.build.assetsRoot, 117 globPatterns: ['**/*.{html,js,css}'], 118 swDest: path.join(config.build.assetsRoot, 'service-worker.js'), 119 skipWaiting: false, 120 clientsClaim: true, 121 runtimeCaching: [ 122 { 123 // APIのキャッシュ 124 urlPattern: /.*api.*/, 125 handler: 'networkFirst', 126 options: { 127 cacheName: 'api', 128 expiration: { 129 maxAgeSeconds: 60 * 60 * 24 130 } 131 } 132 } 133 ] 134 }) 135 ] 136}) 137 138if (config.build.productionGzip) { 139 const CompressionWebpackPlugin = require('compression-webpack-plugin') 140 141 webpackConfig.plugins.push( 142 new CompressionWebpackPlugin({ 143 asset: '[path].gz[query]', 144 algorithm: 'gzip', 145 test: new RegExp( 146 '\.(' + 147 config.build.productionGzipExtensions.join('|') + 148 ')$' 149 ), 150 threshold: 10240, 151 minRatio: 0.8 152 }) 153 ) 154} 155 156if (config.build.bundleAnalyzerReport) { 157 const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 158 webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 159} 160 161module.exports = webpackConfig 162

・config/index.js

javascript

1'use strict' 2 3// see http://vuejs-templates.github.io/webpack for documentation. 4const path = require('path') 5 6module.exports = { 7 build: { 8 env: require('./prod.env'), 9 // index: path.resolve(__dirname, '../dist/index.html'), 10 // assetsRoot: path.resolve(__dirname, '../dist'), 11 index: path.resolve(__dirname, '../docs/index.html'), 12 assetsRoot: path.resolve(__dirname, '../docs'), 13 assetsSubDirectory: 'static', 14 // assetsPublicPath: '/', 15 assetsPublicPath: './', 16 productionSourceMap: true, 17 // Gzip off by default as many popular static hosts such as 18 // Surge or Netlify already gzip all static assets for you. 19 // Before setting to `true`, make sure to: 20 // npm install --save-dev compression-webpack-plugin 21 productionGzip: false, 22 productionGzipExtensions: ['js', 'css'], 23 // Run the build command with an extra argument to 24 // View the bundle analyzer report after build finishes: 25 // `npm run build --report` 26 // Set to `true` or `false` to always turn it on or off 27 bundleAnalyzerReport: process.env.npm_config_report 28 }, 29 dev: { 30 env: require('./dev.env'), 31 port: 8080, 32 autoOpenBrowser: true, 33 assetsSubDirectory: 'static', 34 assetsPublicPath: '/', 35 proxyTable: {}, 36 // CSS Sourcemaps off by default because relative paths are "buggy" 37 // with this option, according to the CSS-Loader README 38 // (https://github.com/webpack/css-loader#sourcemaps) 39 // In our experience, they generally work as expected, 40 // just be aware of this issue when enabling this option. 41 cssSourceMap: false 42 } 43} 44

お手数ですが、考えられる問題点やVueCLI導入時の留意点などをご教示していただきたいです。
また、コードの変更以外にも途中でプロジェクト名(フォルダとプロジェクト名がかかれた実装部)を手動で変更した経緯があります。

宜しくお願い致します。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

レイアウトを一式変更したところ解消されました。

投稿2018/04/14 08:13

street

総合スコア34

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.29%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問