Linux下VUE环境搭建步骤

1. 在线安装rz命令

# yum install lrzsz

2. 下载并安装node

从nodejs官网下载node二进制安装包:node-v12.16.1-linux-x64.tar.xz。
通过rz命令上传。
执行解压命令,将文件解压到 /export/server/ 路径下。

# tar xvf node-v12.16.1-linux-x64.tar.xz

3. 创建软连接

# ln -s -b /export/servers/node-v12.16.1-linux-x64/bin/node /usr/local/bin
# node --version
v12.16.1
# ln -s -b /export/servers/node-v12.16.1-linux-x64/bin/npm /usr/local/bin
# npm --version
6.13.4

4. 安装 gcc & g++

yum install gcc
yum install gcc-c++ libstdc++-devel 

5. 关于执行用户

npm 出于安全考虑不支持以 root 用户运行,即使你用 root 用户身份运行了,npm 会自动转成一个叫 nobody 的用户来运行,而这个用户几乎没有任何权限。这样的话如果你脚本里有一些需要权限的操作,比如写文件(尤其是写 /root/.node-gyp),就会崩掉了。

为了避免这种情况,要么按照 npm 的规矩来,专门建一个用于运行 npm 的高权限用户;要么加 --unsafe-perm 参数,这样就不会切换到 nobody 上,运行时是哪个用户就是哪个用户,即是 root。

6. 执行 npm install

6.1 问题清单 & 解决方案

6.1.1 phantomjs

Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1496325965675/phantomjs-2.1.1-linux-x86_64' -> '/XXX/node_modules/phantomjs-prebuilt/lib/phantom'
    at Error (native)

#下载
wget https://npm.taobao.org/mirrors/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
tar -jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2
#加入环境变量
vim /etc/profile
#末尾加入,注意文件路径
export PATH=$PATH:/usr/local/phantomjs-2.1.1-linux-x86_64/bin
#执行
source /etc/profile

6.1.2 webpack4.0中使用“extract-text-webpack-plugin”报错

Error: Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead

解决方案:extract-text-webpack-plugin咱不支持webpack4.0,可以执行以下命令解决。

npm install extract-text-webpack-plugin@next

6.1.3 node-sass

Error: ENOENT: no such file or directory, scandir 

解决方案:

npm rebuild node-sass

6.1.4 … 扩展运算符时报错 Syntax Error: Unexpected token

压缩解压过程中.babelrc文件丢失问题

6.1.5 ‘src’ of img tag become src="[object Module]" in browser

Workaround: set the esModule option in url-loader to false.

It’s because in @vue/component-compiler-utils we transformed the asset urls to require statements, which expect CommonJS modules, while the recent major release of url-loader emits ES modules by default.

6.1.6 使用MiniCssExtractPlugin后样式丢失

配置Plugin时要保持输入输出路径的一致。

new MiniCssExtractPlugin({
      // Options similar to the same options in webpackOptions.output
      // both options are optional
      filename: devMode ? utils.assetsPath('css/[name].css') : utils.assetsPath('css/[name].[hash].css'),
      chunkFilename: devMode ? utils.assetsPath('css/[id].css') : utils.assetsPath('css/[id].[hash].css'),
    }),

7. vue-loader配置参考

module: {
    rules: [
      // ...(config.dev.useEslint ? [createLintingRule()] : []),
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: vueLoaderConfig
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: file => (
          /node_modules/.test(file) &&
          !/\.vue\.js/.test(file)
        )
      },
      {
        test: /\.css$/,
        use: [
          process.env.NODE_ENV !== 'production'
            ? 'vue-style-loader'
            : MiniCssExtractPlugin.loader,
          'css-loader',
          { 
            loader: 'postcss-loader',
            options: {
              sourceMap: true,
            }
          }
        ]
      },
      {
        test: /\.sass$/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: 'postcss-loader',
            options: {
              parser: 'postcss-sass',
              sourceMap: true,
              // conf: {
              //   path: 'postcss.config.js'
              // }
            }
          },
          {
            loader: 'sass-loader',
            options: {
              indentedSyntax: true,
              // sass-loader version >= 8
              sassOptions: {
                indentedSyntax: true
              },
            }
          }
        ]
      },
      {
        test: /\.scss$/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: 'postcss-loader',
            options: {
              parser: 'postcss-scss',
              sourceMap: true,
              // conf: {
              //   path: 'postcss.config.js'
              // }
            }
          },
          {
            loader: 'sass-loader',
            options: { 
              prependData: `$color: red;`,
              sourceMap: true 
            }
          }
        ]
      },
      {
        test: /\.less$/,
        use: [
          'style-loader',
          {
            loader: 'css-loader',
            options: {
              importLoaders: 1,
            }
          },
          {
            loader: 'postcss-loader',
            options: {
              parser: 'postcss-less',
              sourceMap: true,
              // conf: {
              //   path: 'postcss.config.js'
              // }
            }
          },
          {
            loader: 'less-loader',
            options: {
              sourceMap: true,
            }
          }
        ]
      },
      {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('img/[name].[hash:7].[ext]')
        }
      },
      {
        test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('media/[name].[hash:7].[ext]')
        }
      },
      {
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
        }
      }
    ]
  },

参考

http://sansantao.com/archives/29.html
Linux安装gcc和g++
https://blog.csdn.net/shine_a/article/details/103133384
https://blog.csdn.net/qq_31325079/article/details/102565223
https://blog.csdn.net/zyx527734377/article/details/98640617
https://segmentfault.com/a/1190000013998339?utm_source=tag-newest
https://www.jianshu.com/p/eb7269efdfa0
https://blog.csdn.net/weixin_42470791/article/details/82943777
https://blog.csdn.net/xiaohuangdilhd/article/details/84310297
https://blog.csdn.net/weixin_29491885/article/details/100972535
‘src’ of img tag become src="[object Module]" in browser

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要搭建Python Vue开发环境,你需要安装Python和Vue的相关工具和库。下面是一个简单的步骤: 1. 安装Python:首先,你需要安装Python解释器。你可以从Python官方网站(https://www.python.org)下载适合你操作系统的Python版本,并按照安装向导进行安装。 2. 安装pip:pip是Python的包管理工具,用于安装和管理Python库。在安装Python时,通常会自动安装pip。你可以在命令行中运行`pip --version`来检查是否已安装。 3. 安装Vue CLI:Vue CLI是一个用于快速搭建Vue项目的命令行工具。你可以使用npm(Node.js包管理工具)来安装Vue CLI。首先,确保你已经安装了Node.js(https://nodejs.org),然后在命令行中运行`npm install -g @vue/cli`来全局安装Vue CLI。 4. 创建Vue项目:在命令行中,进入你想要创建Vue项目的目录,并运行`vue create <project-name>`来创建一个新的Vue项目。根据提示选择你需要的配置选项。 5. 运行Vue项目:进入项目目录,运行`npm run serve`来启动开发服务器。然后,你可以在浏览器中访问`http://localhost:8080`来查看你的Vue应用程序。 6. 安装Python虚拟环境:为了隔离不同项目的Python依赖,建议使用Python虚拟环境。在项目目录中,运行`python -m venv <venv-name>`来创建一个新的虚拟环境。然后,激活虚拟环境,Windows系统运行`<venv-name>\Scripts\activate`,Linux/Mac系统运行`source <venv-name>/bin/activate`。 7. 安装Python依赖:在虚拟环境中,使用pip安装你需要的Python库。例如,运行`pip install flask`来安装Flask库。 现在,你已经成功搭建了Python Vue开发环境,并可以开始开发你的应用程序了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值