vue.config.js中配置coffee-loader

7 篇文章 0 订阅

安装coffeescript和coffee-loader后

const path = require('path')
const resolve = (file) => {
	return path.resolve(__dirname, file)
}
let isProduction = process.env.NODE_ENV === 'production' ? true : false
const configs = {
	publicPath: isProduction ? 'xiangmu': '/' ,//替代baseUrl,默认是/
	outputDir: 'dist',//默认是dist,会自动清空dist目录下的文件,再次创建新的。
	assetsDir: '',//放置静态资源的目录,默认为空。
	indexPath: 'index.html',//默认为index.html
	filenameHashing: true,//文件 名包含hash,控制缓存,默认是true,
	//pages多页配置
	productionSourceMap: isProduction ? false : true,
	//crossorigin跨域配置,
	//loader也可以配置在这里。但是我配置在chainWebpack中。
	configureWebpack: (config) => {
		if(isProduction) {
			config.mode = 'production'
		} else {
			config.mode = 'development'
		}
		config = {
			...,
			resolve: {
				alias: {
					'@': resolve('./src')
				}
			}
		}
	},
	parallel: require('os').cpus().length>1, //多核配置,构建的适合快点。
	devServe: {
		open: process.plateform === 'darwin',
		host: '0.0.0.0',
		port: 7777,
		https: false,
		hotOnly: false,
		proxy: null,
		before: app => {}
	},
	//移动端适配
	css: {
		loaderOptions: {
			css: {},
			postcss: {
				plugins: [
					requires('postcss-px2rem')({
						remUnit: 75,
						baseDpr:1
					})
				]
			}
		}
	},
	//coffee-loader配置,
	chainWebpack: (config) => {
		config.module
			.rule('coffee')
			.test('/\.coffee$/')
			.use('coffee-loader')
				.loader('coffee-loader')
				.end()
	}
}
module.exports = configs

vue文件
单文件形式Home.vue

<template>
	<div class="home">
		<ul>
			<li  v-for="(v, i) in arr" :key="i">
				{{v}}, {{say(i)}}
			</li>
		</ul>
	</div>
</template>
<script lang="coffee">
	export default
		data:->
			arr: [1..10]
		methods: 
			say: (x) -> x * x
</script>

项目中使用了eslint,其实没有必要,因为和python一样,coffeescript和ruby这种都是强缩进的,格式其实不用eslint约束就已经能非常好看了。
但是还是配吧。
可以看官网https://github.com/a-x-/eslint-plugin-coffeescript
.eslintrc.js

module.exports = {
	root: true,
	env: {
		node: true
	},
	extends: [
		'plugins;vue/essential',
		‘@vue/standard’
	],
	plugins: ['coffeescript'],
	rules: {
		'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
		"no-debugger": process.env.NODE_ENV === 'productioin' ? 'error': off'
	},
	parser: 'eslint-plugin-coffeescript',
	parserOptions: {
		parser: 'babel-eslint',
		sourceType: 'module',
		esmaVersion: 6
	}
}

暂时先配这些。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值