서브디렉토리에서 Vue.js 웹팩 프로젝트를 처리하는 방법
해결책을 찾기 위해 몇 시간 동안 찾아봤지만 떠오르지 않았어요.아래 그림과 같이 Vue.js 2 + webpack (Webpack 템플릿 사용)을 기반으로 한 프로젝트가 있습니다.
에는 두 .src/assets/
★★★★★★★★★★★★★★★★★」static
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★src/assets/
는 웹 에 의해 되며, 에 로 로드됩니다.static/
그대로 로딩됩니다(잘못된 경우 정정 또는 오해한 정보를 보완해 주십시오).하지만 이 정보에도 불구하고, 나는 내가 필요한 것을 얻을 방법을 찾을 수 없었다.
문제는 다음과 같습니다.
을 dist dist dist addirectory와 같은 .mydomain.com/subdirectory
은 지 but, 가가 but but but but, are but but but but but but but but but but but but but에서 직접 로딩됩니다.mydomain.com/static/
이 mydomain.com/subdirectory/static/
.
assetsSubDirectory
★★★★★★★★★★★★★★★★★」assetsPublicPath
build
config/index.js
파일(아래 그림 참조)을 몇 가지 방법으로 작성했지만 실제로 필요한 것을 얻을 수 없었습니다.이미지 및 css 파일이 올바른 위치에서 로드될 수 있지만 웹 팩에 의해 생성된 JS 파일은 로드되지 않거나 그 반대일 수 있습니다.
// see http://vuejs-templates.github.io/webpack for documentation.
var path = require('path')
module.exports = {
build: {
env: require('./prod.env'),
index: path.resolve(__dirname, '../dist/index.html'),
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/',
productionSourceMap: true,
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css'],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report
},
dev: {
env: require('./dev.env'),
port: 8080,
autoOpenBrowser: true,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
// CSS Sourcemaps off by default because relative paths are "buggy"
// with this option, according to the CSS-Loader README
// (https://github.com/webpack/css-loader#sourcemaps)
// In our experience, they generally work as expected,
// just be aware of this issue when enabling this option.
cssSourceMap: false
}
}
vue-cli를 사용하고 있습니다.
다음과 같이 빌드 속성을 설정합니다.
assetsSubDirectory: 'subdirectory/static/',
assetsPublicPath: '/',
그 후 실행
npm run build
다음과 같은 dist 폴더가 나타납니다.
.
├── index.html
└── subdirectory
└── static
├── css
│ ├── app.201d8caff7556318f5a3e08a46cb487d.css
│ └── app.201d8caff7556318f5a3e08a46cb487d.css.map
└── js
├── app.be4eeaeed988e54df219.js
├── app.be4eeaeed988e54df219.js.map
├── manifest.116a87efb9d4edc91c95.js
├── manifest.116a87efb9d4edc91c95.js.map
├── vendor.8659787d0b39fda686fd.js
└── vendor.8659787d0b39fda686fd.js.map
다음과 같이 config/index.dir를 변경하여 현재 dir를 기준으로 참조합니다.
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: './static',
assetsPublicPath: './',
언급URL : https://stackoverflow.com/questions/45984318/how-to-serve-a-vue-js-webpack-project-from-a-subdirectory
'sourcecode' 카테고리의 다른 글
LD_PRELOAD를 사용하여 여러 파일 지정 (0) | 2022.08.12 |
---|---|
연결 Java - MySQL: 공용 키 검색이 허용되지 않습니다. (0) | 2022.08.12 |
새 텍스트 상자 Vue3을 추가할 번호를 입력합니다. (0) | 2022.08.10 |
C++에서의 디버깅 매크로 (0) | 2022.08.10 |
브라우저 콘솔에서 VueJs $watch 트리거가 작동하지 않음 (0) | 2022.08.10 |