sourcecode

서브디렉토리에서 Vue.js 웹팩 프로젝트를 처리하는 방법

copyscript 2022. 8. 12. 23:32
반응형

서브디렉토리에서 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

반응형