安装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
}
}
暂时先配这些。