首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Django中使用vue开发模式

如何在Django中使用vue开发模式
EN

Stack Overflow用户
提问于 2020-10-07 06:43:22
回答 1查看 48关注 0票数 0

我不知道如何使用Django运行开发模式。我正在运行webpack,当我完成所有Vuejs的工作时,我只需将所有内容捆绑到一个文件夹中,Django将其作为静态文件提供服务。我知道我必须用模式开发来运行webpack,但这不起作用,它给了我一个找不到的错误。我想和Django一起在开发模式下运行Vuejs,我该怎么做呢?我会分享我的项目结构,我的package.json和webpack的配置。

代码语言:javascript
复制
const path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin');

module.exports = {
    entry: './frontend/Vue/main.js',
    output: {
        filename: 'build.js',
        path: path.resolve(__dirname, './static/js'),
        publicPath: '/static/js'
    },
    module: {
        rules: [
            {
                test: /\.(js)$/,
                exclude: /(node_modules)/,
                use: [
                    { loader: 'babel-loader' }
                ]
            },
            {
                test: /\.(css|scss)/,
                use: [
                    'style-loader'
                ]
            },
            {
                test: /\.vue$/,
                exclude: /node_modules/,
                loader: 'vue-loader'
            }
        ]
    },
    devServer: {
        // contentBase: ponerle la ruta del index de django
        contentBase: path.join(__dirname, 'templates'),
        watchContentBase: true,
        historyApiFallback: true,
        noInfo: true
      },
    plugins: [
        new VueLoaderPlugin()
    ]
}

package.json

代码语言:javascript
复制
{
  "name": "TuDistribuidora",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "webpack-dev-server --mode development --port 9000 --open",
    "build": "webpack --progress"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/EmiBuffet/TuDistribuidora.git"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/EmiBuffet/TuDistribuidora/issues"
  },
  "homepage": "https://github.com/EmiBuffet/TuDistribuidora#readme",
  "dependencies": {
    "vue": "^2.6.11",
    "vue-router": "^3.4.5",
    "vuex": "^3.5.1"
  },
  "devDependencies": {
    "@babel/core": "^7.11.1",
    "babel-loader": "^8.1.0",
    "babel-preset-es2015": "^6.24.1",
    "node-sass": "^4.14.1",
    "sass-loader": "^9.0.3",
    "style-loader": "^1.2.1",
    "vue-loader": "^15.9.3",
    "vue-style-loader": "^4.1.2",
    "vue-template-compiler": "^2.6.11",
    "webpack": "^4.44.1",
    "webpack-cli": "^3.3.12",
    "webpack-dev-server": "^3.11.0",
    "bulma": "^0.9.1"
  }
}

项目结构:

EN

回答 1

Stack Overflow用户

发布于 2020-10-07 16:40:41

在您的Django项目中使用django-webpack-loader,并在您的webpack构建中结合使用webpack捆绑跟踪器,将提供在生产/开发Vue构建之间快速切换所需的连接。捆绑包信息将由webpack记录到一个webpack-stats.json中,然后Django将使用它来获取/加载给定视图的正确捆绑包。

我有一台article explaining step-by-step how to set up a project with the above techniques

好样的!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64234772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档