pageage.json就是没有px2rem

pageage.json就是没有px2rem

pageae.json

{

"name": "my-vue",

"version": "1.0.0",

"description": "A Vue.js project",

"author": "linuolan",

"private": true,

"scripts": {

"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",

"start": "npm run dev",

"unit": "jest --config test/unit/jest.conf.js --coverage",

"e2e": "node test/e2e/runner.js",

"test": "npm run unit && npm run e2e",

"lint": "eslint --ext .js,.vue src test/unit test/e2e/specs",

"build": "node build/build.js"

},

"dependencies": {

"vue": "^2.5.2",

"vue-resource": "^1.5.1",

"vue-router": "^3.0.1",

"vuex": "^3.1.1"

},

"devDependencies": {

"autoprefixer": "^7.1.2",

"babel-core": "^6.22.1",

"babel-eslint": "^8.2.1",

"babel-helper-vue-jsx-merge-props": "^2.0.3",

"babel-jest": "^21.0.2",

"babel-loader": "^7.1.1",

"babel-plugin-dynamic-import-node": "^1.2.0",

"babel-plugin-syntax-jsx": "^6.18.0",

"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",

"babel-plugin-transform-runtime": "^6.22.0",

"babel-plugin-transform-vue-jsx": "^3.5.0",

"babel-preset-env": "^1.3.2",

"babel-preset-stage-2": "^6.22.0",

"babel-register": "^6.22.0",

"chalk": "^2.0.1",

"chromedriver": "^2.27.2",

"copy-webpack-plugin": "^4.0.1",

"cross-spawn": "^5.0.1",

"css-loader": "^0.28.0",

"eslint": "^4.15.0",

"eslint-config-standard": "^10.2.1",

"eslint-friendly-formatter": "^3.0.0",

"eslint-loader": "^1.7.1",

"eslint-plugin-import": "^2.7.0",

"eslint-plugin-node": "^5.2.0",

"eslint-plugin-promise": "^3.4.0",

"eslint-plugin-standard": "^3.0.1",

"eslint-plugin-vue": "^4.0.0",

"extract-text-webpack-plugin": "^3.0.0",

"file-loader": "^1.1.4",

"friendly-errors-webpack-plugin": "^1.6.1",

"html-webpack-plugin": "^2.30.1",

"jest": "^22.0.4",

"jest-serializer-vue": "^0.3.0",

"nightwatch": "^0.9.12",

"node-notifier": "^5.1.2",

"optimize-css-assets-webpack-plugin": "^3.2.0",

"ora": "^1.2.0",

"portfinder": "^1.0.13",

"postcss-import": "^11.0.0",

"postcss-loader": "^2.0.8",

"postcss-url": "^7.2.1",

"rimraf": "^2.6.0",

"selenium-server": "^3.0.1",

"semver": "^5.3.0",

"shelljs": "^0.7.6",

"uglifyjs-webpack-plugin": "^1.1.1",

"url-loader": "^0.5.8",

"vue-jest": "^1.0.2",

"vue-loader": "^13.3.0",

"vue-style-loader": "^3.0.1",

"vue-template-compiler": "^2.5.2",

"webpack": "^3.6.0",

"webpack-bundle-analyzer": "^2.9.0",

"webpack-dev-server": "^2.9.1",

"webpack-merge": "^4.1.0"

},

"engines": {

"node": ">= 6.0.0",

"npm": ">= 3.0.0"

},

"browserslist": [

"> 1%",

"last 2 versions",

"not ie <= 8"

]

}

utils.js

'use strict'

const path = require('path')

const config = require('../config')

const ExtractTextPlugin = require('extract-text-webpack-plugin')

const packageConfig = require('../package.json')


exports.assetsPath = function (_path) {

const assetsSubDirectory = process.env.NODE_ENV === 'production'

? config.build.assetsSubDirectory

: config.dev.assetsSubDirectory


return path.posix.join(assetsSubDirectory, _path)

}


exports.cssLoaders = function (options) {

options = options || {}


const cssLoader = {

loader: 'css-loader',

options: {

sourceMap: options.sourceMap

}

}


const postcssLoader = {

loader: 'postcss-loader',

options: {

sourceMap: options.sourceMap

}

}

var px2remLoader = {

loader: 'px2rem-loader',

options: {

remUnin: 50

}

}

// generate loader string to be used with extract text plugin

function generateLoaders (loader, loaderOptions) {

const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader, px2remLoader]


if (loader) {

loaders.push({

loader: loader + '-loader',

options: Object.assign({}, loaderOptions, {

sourceMap: options.sourceMap

})

})

}


// Extract CSS when that option is specified

// (which is the case during production build)

if (options.extract) {

return ExtractTextPlugin.extract({

use: loaders,

fallback: 'vue-style-loader'

})

} else {

return ['vue-style-loader'].concat(loaders)

}

}


// https://vue-loader.vuejs.org/en/configurations/extract-css.html

return {

css: generateLoaders(),

postcss: generateLoaders(),

less: generateLoaders('less'),

sass: generateLoaders('sass', { indentedSyntax: true }),

scss: generateLoaders('sass'),

stylus: generateLoaders('stylus'),

styl: generateLoaders('stylus')

}

}


// Generate loaders for standalone style files (outside of .vue)

exports.styleLoaders = function (options) {

const output = []

const loaders = exports.cssLoaders(options)


for (const extension in loaders) {

const loader = loaders[extension]

output.push({

test: new RegExp('\\.' + extension + '$'),

use: loader

})

}


return output

}


exports.createNotifierCallback = () => {

const notifier = require('node-notifier')


return (severity, errors) => {

if (severity !== 'error') return


const error = errors[0]

const filename = error.file && error.file.split('!').pop()


notifier.notify({

title: packageConfig.name,

message: severity + ': ' + error.name,

subtitle: filename || '',

icon: path.join(__dirname, 'logo.png')

})

}

}


dataile

<template>

<div class='detail-page'>

detail

</div>

</template>

<style scoped>

.detail-page{

width:30px;

}

</style>


正在回答

登陆购买课程后可参与讨论,去登陆

2回答

同学你好,安装完之后。要在build文件夹下的utils.js文件中进行配置,且配置之后需要退出项目的运行,重新启动项目哦。

http://img1.sycdn.imooc.com//climg/5d417626000139e417090509.jpg

希望能帮助到你,祝学习愉快!

好帮手慕糖 2019-07-31 11:48:41

同学你好,是的哦,pageage.json这个文件中是没有的,在安装的时候,添加--save才可以保存到pageage.json中哦。

即:npm i px2rem-loader --save

另,如果将所有依赖删除重新安装的话,那么px2rem-loader插件也需要手动重新安装一次,因为package.json中没有记录,所以不会自动安装。

希望能帮助到你,欢迎采纳。

祝学习愉快!

  • 提问者 空洞L #1
    那为什么我的页面没有px变rem
    2019-07-31 12:03:21
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师