From 2816c5687d92ee2be847109ec9158e1559646a79 Mon Sep 17 00:00:00 2001 From: outofcash Date: Wed, 4 Oct 2017 23:53:12 +0200 Subject: [PATCH 1/3] Support for .coffee files for store and middlewares --- lib/app/middleware.js | 4 ++-- lib/app/store.js | 4 ++-- lib/builder/webpack/base.config.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/app/middleware.js b/lib/app/middleware.js index 57e04073cb..30d6482c4a 100644 --- a/lib/app/middleware.js +++ b/lib/app/middleware.js @@ -1,5 +1,5 @@ <% if (middleware) { %> -let files = require.context('@/middleware', false, /^\.\/.*\.(js|ts)$/) +let files = require.context('@/middleware', false, /^\.\/.*\.(js|ts|coffee)$/) let filenames = files.keys() function getModule (filename) { @@ -12,7 +12,7 @@ let middleware = {} // Generate the middleware for (let filename of filenames) { - let name = filename.replace(/^\.\//, '').replace(/\.(js|ts)$/, '') + let name = filename.replace(/^\.\//, '').replace(/\.(js|ts|coffee)$/, '') middleware[name] = getModule(filename) } diff --git a/lib/app/store.js b/lib/app/store.js index d1e59efcd6..308b3bc88d 100644 --- a/lib/app/store.js +++ b/lib/app/store.js @@ -4,7 +4,7 @@ import Vuex from 'vuex' Vue.use(Vuex) // Recursive find files in {srcDir}/store -const files = require.context('@/store', true, /^\.\/.*\.(js|ts)$/) +const files = require.context('@/store', true, /^\.\/.*\.(js|ts|coffee)$/) const filenames = files.keys() // Store @@ -30,7 +30,7 @@ if (typeof storeData !== 'function') { } for (let filename of filenames) { - let name = filename.replace(/^\.\//, '').replace(/\.(js|ts)$/, '') + let name = filename.replace(/^\.\//, '').replace(/\.(js|ts|coffee)$/, '') if (name === 'index') continue let namePath = name.split(/\//) diff --git a/lib/builder/webpack/base.config.js b/lib/builder/webpack/base.config.js index 3da78d2640..6c14649c13 100644 --- a/lib/builder/webpack/base.config.js +++ b/lib/builder/webpack/base.config.js @@ -35,7 +35,7 @@ export default function webpackBaseConfig (name) { hints: this.options.dev ? false : 'warning' }, resolve: { - extensions: ['.js', '.json', '.vue', '.ts'], + extensions: ['.js', '.json', '.vue', '.ts', '.coffee'], alias: { '~': join(this.options.srcDir), '~~': join(this.options.rootDir), @@ -43,7 +43,7 @@ export default function webpackBaseConfig (name) { '@@': join(this.options.rootDir), // Used by vue-loader so we can use in templates - // with + // with 'assets': join(this.options.srcDir, 'assets'), 'static': join(this.options.srcDir, 'static') }, From a461ae83ec515e99cd62de18a2c4ded2f5381ef4 Mon Sep 17 00:00:00 2001 From: outofcash Date: Fri, 13 Oct 2017 14:10:24 +0200 Subject: [PATCH 2/3] CoffeeScript example. --- examples/with-coffee/.editorconfig | 13 ++++ examples/with-coffee/.eslintrc.js | 16 +++++ examples/with-coffee/.gitignore | 11 +++ examples/with-coffee/README.md | 22 ++++++ examples/with-coffee/assets/README.md | 8 +++ examples/with-coffee/components/Logo.vue | 79 ++++++++++++++++++++++ examples/with-coffee/components/README.md | 6 ++ examples/with-coffee/layouts/README.md | 8 +++ examples/with-coffee/layouts/default.vue | 52 ++++++++++++++ examples/with-coffee/middleware/README.md | 9 +++ examples/with-coffee/nuxt.config.js | 31 +++++++++ examples/with-coffee/package.json | 31 +++++++++ examples/with-coffee/pages/README.md | 7 ++ examples/with-coffee/pages/index.vue | 58 ++++++++++++++++ examples/with-coffee/plugins/README.md | 8 +++ examples/with-coffee/static/README.md | 11 +++ examples/with-coffee/static/favicon.ico | Bin 0 -> 1150 bytes examples/with-coffee/store/README.md | 10 +++ examples/with-coffee/store/index.coffee | 2 + 19 files changed, 382 insertions(+) create mode 100644 examples/with-coffee/.editorconfig create mode 100644 examples/with-coffee/.eslintrc.js create mode 100644 examples/with-coffee/.gitignore create mode 100644 examples/with-coffee/README.md create mode 100644 examples/with-coffee/assets/README.md create mode 100644 examples/with-coffee/components/Logo.vue create mode 100644 examples/with-coffee/components/README.md create mode 100644 examples/with-coffee/layouts/README.md create mode 100644 examples/with-coffee/layouts/default.vue create mode 100644 examples/with-coffee/middleware/README.md create mode 100644 examples/with-coffee/nuxt.config.js create mode 100644 examples/with-coffee/package.json create mode 100644 examples/with-coffee/pages/README.md create mode 100644 examples/with-coffee/pages/index.vue create mode 100644 examples/with-coffee/plugins/README.md create mode 100644 examples/with-coffee/static/README.md create mode 100644 examples/with-coffee/static/favicon.ico create mode 100644 examples/with-coffee/store/README.md create mode 100644 examples/with-coffee/store/index.coffee diff --git a/examples/with-coffee/.editorconfig b/examples/with-coffee/.editorconfig new file mode 100644 index 0000000000..9142239769 --- /dev/null +++ b/examples/with-coffee/.editorconfig @@ -0,0 +1,13 @@ +# editorconfig.org +root = true + +[*] +indent_size = 2 +indent_style = space +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/examples/with-coffee/.eslintrc.js b/examples/with-coffee/.eslintrc.js new file mode 100644 index 0000000000..b44e099cbb --- /dev/null +++ b/examples/with-coffee/.eslintrc.js @@ -0,0 +1,16 @@ +module.exports = { + root: true, + parser: 'babel-eslint', + env: { + browser: true, + node: true + }, + extends: 'standard', + // required to lint *.vue files + plugins: [ + 'html' + ], + // add your custom rules here + rules: {}, + globals: {} +} diff --git a/examples/with-coffee/.gitignore b/examples/with-coffee/.gitignore new file mode 100644 index 0000000000..7ee6115053 --- /dev/null +++ b/examples/with-coffee/.gitignore @@ -0,0 +1,11 @@ +# dependencies +node_modules + +# logs +npm-debug.log + +# Nuxt build +.nuxt + +# Nuxt generate +dist diff --git a/examples/with-coffee/README.md b/examples/with-coffee/README.md new file mode 100644 index 0000000000..601a17bbb6 --- /dev/null +++ b/examples/with-coffee/README.md @@ -0,0 +1,22 @@ +# with-coffee + +> Nuxt.js project + +## Build Setup + +``` bash +# install dependencies +$ npm install # Or yarn install + +# serve with hot reload at localhost:3000 +$ npm run dev + +# build for production and launch server +$ npm run build +$ npm start + +# generate static project +$ npm run generate +``` + +For detailed explanation on how things work, checkout the [Nuxt.js docs](https://github.com/nuxt/nuxt.js). diff --git a/examples/with-coffee/assets/README.md b/examples/with-coffee/assets/README.md new file mode 100644 index 0000000000..c67cf2e260 --- /dev/null +++ b/examples/with-coffee/assets/README.md @@ -0,0 +1,8 @@ +# ASSETS + +This directory contains your un-compiled assets such as LESS, SASS, or JavaScript. + +More information about the usage of this directory in the documentation: +https://nuxtjs.org/guide/assets#webpacked + +**This directory is not required, you can delete it if you don't want to use it.** diff --git a/examples/with-coffee/components/Logo.vue b/examples/with-coffee/components/Logo.vue new file mode 100644 index 0000000000..0b8733dc9b --- /dev/null +++ b/examples/with-coffee/components/Logo.vue @@ -0,0 +1,79 @@ + + + diff --git a/examples/with-coffee/components/README.md b/examples/with-coffee/components/README.md new file mode 100644 index 0000000000..d7768ddb5f --- /dev/null +++ b/examples/with-coffee/components/README.md @@ -0,0 +1,6 @@ +# COMPONENTS + +The components directory contains your Vue.js Components. +Nuxt.js doesn't supercharge these components. + +**This directory is not required, you can delete it if you don't want to use it.** diff --git a/examples/with-coffee/layouts/README.md b/examples/with-coffee/layouts/README.md new file mode 100644 index 0000000000..83d09caee8 --- /dev/null +++ b/examples/with-coffee/layouts/README.md @@ -0,0 +1,8 @@ +# LAYOUTS + +This directory contains your Application Layouts. + +More information about the usage of this directory in the documentation: +https://nuxtjs.org/guide/views#layouts + +**This directory is not required, you can delete it if you don't want to use it.** diff --git a/examples/with-coffee/layouts/default.vue b/examples/with-coffee/layouts/default.vue new file mode 100644 index 0000000000..a749bdd457 --- /dev/null +++ b/examples/with-coffee/layouts/default.vue @@ -0,0 +1,52 @@ + + + diff --git a/examples/with-coffee/middleware/README.md b/examples/with-coffee/middleware/README.md new file mode 100644 index 0000000000..edb9129e28 --- /dev/null +++ b/examples/with-coffee/middleware/README.md @@ -0,0 +1,9 @@ +# MIDDLEWARE + +This directory contains your Application Middleware. +The middleware lets you define custom function to be ran before rendering a page or a group of pages (layouts). + +More information about the usage of this directory in the documentation: +https://nuxtjs.org/guide/routing#middleware + +**This directory is not required, you can delete it if you don't want to use it.** diff --git a/examples/with-coffee/nuxt.config.js b/examples/with-coffee/nuxt.config.js new file mode 100644 index 0000000000..f409fceff7 --- /dev/null +++ b/examples/with-coffee/nuxt.config.js @@ -0,0 +1,31 @@ +module.exports = { + /* + ** Headers of the page + */ + head: { + title: 'with-coffee', + meta: [ + { charset: 'utf-8' }, + { name: 'viewport', content: 'width=device-width, initial-scale=1' }, + { hid: 'description', name: 'description', content: 'Nuxt.js project' } + ], + link: [ + { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } + ] + }, + /* + ** Customize the progress bar color + */ + loading: { color: '#3B8070' }, + /* + ** Build configuration + */ + build: { + extend (config, ctx) { + config.module.rules.push({ + test: /\.coffee$/, + loader: 'coffee-loader' + }) + } + } +} diff --git a/examples/with-coffee/package.json b/examples/with-coffee/package.json new file mode 100644 index 0000000000..7554f4a84e --- /dev/null +++ b/examples/with-coffee/package.json @@ -0,0 +1,31 @@ +{ + "name": "with-coffee", + "version": "1.0.0", + "description": "Nuxt.js with CoffeeScript", + "author": "Alex Ananiev ", + "private": true, + "scripts": { + "dev": "nuxt", + "build": "nuxt build", + "start": "nuxt start", + "generate": "nuxt generate", + "lint": "eslint --ext .js,.vue --ignore-path .gitignore .", + "precommit": "npm run lint" + }, + "dependencies": { + "nuxt": "latest" + }, + "devDependencies": { + "babel-eslint": "^7.2.3", + "coffee-loader": "^0.8.0", + "coffeescript": "^2.0.1", + "eslint": "^4.3.0", + "eslint-config-standard": "^10.2.1", + "eslint-loader": "^1.9.0", + "eslint-plugin-html": "^3.1.1", + "eslint-plugin-import": "^2.7.0", + "eslint-plugin-node": "^5.1.1", + "eslint-plugin-promise": "^3.5.0", + "eslint-plugin-standard": "^3.0.1" + } +} diff --git a/examples/with-coffee/pages/README.md b/examples/with-coffee/pages/README.md new file mode 100644 index 0000000000..3c7faf56e7 --- /dev/null +++ b/examples/with-coffee/pages/README.md @@ -0,0 +1,7 @@ +# PAGES + +This directory contains your Application Views and Routes. +The framework reads all the .vue files inside this directory and create the router of your application. + +More information about the usage of this directory in the documentation: +https://nuxtjs.org/guide/routing diff --git a/examples/with-coffee/pages/index.vue b/examples/with-coffee/pages/index.vue new file mode 100644 index 0000000000..62f9e08b7e --- /dev/null +++ b/examples/with-coffee/pages/index.vue @@ -0,0 +1,58 @@ + + + + + diff --git a/examples/with-coffee/plugins/README.md b/examples/with-coffee/plugins/README.md new file mode 100644 index 0000000000..ec39a25e3f --- /dev/null +++ b/examples/with-coffee/plugins/README.md @@ -0,0 +1,8 @@ +# PLUGINS + +This directory contains your Javascript plugins that you want to run before instantiating the root vue.js application. + +More information about the usage of this directory in the documentation: +https://nuxtjs.org/guide/plugins + +**This directory is not required, you can delete it if you don't want to use it.** diff --git a/examples/with-coffee/static/README.md b/examples/with-coffee/static/README.md new file mode 100644 index 0000000000..66fe23aac1 --- /dev/null +++ b/examples/with-coffee/static/README.md @@ -0,0 +1,11 @@ +# STATIC + +This directory contains your static files. +Each file inside this directory is mapped to /. + +Example: /static/robots.txt is mapped as /robots.txt. + +More information about the usage of this directory in the documentation: +https://nuxtjs.org/guide/assets#static + +**This directory is not required, you can delete it if you don't want to use it.** diff --git a/examples/with-coffee/static/favicon.ico b/examples/with-coffee/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..382fecbbf96d6e1e614e0e2cc8b73e355bd946cc GIT binary patch literal 1150 zcmZQzU<5(|0R|wcz>vYhz#zuJz@P!dKp~(AL>x#lFaYI-8)(_-RMWh}@jndLuXgyK z;A{Fn&J#OMi823Q&|nS5g-td!^Y-RSMpI2!G(|^BVz5@p+ zJll3Uhal^3+~)80K_I1H1Blkn|X#f`-nA@7V7^0XJCNg21cM?f%pJ31V3PB ZU;yC{{0s~~ + message: 'Hello CoffeeScript!' From f74457c9c5850e1c982964f624138a2f9127ab57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Fri, 5 Jan 2018 08:20:32 +0100 Subject: [PATCH 3/3] Add .coffee extensions for nuxt and webpack --- examples/with-coffee/nuxt.config.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/with-coffee/nuxt.config.js b/examples/with-coffee/nuxt.config.js index f409fceff7..f2899df1f1 100644 --- a/examples/with-coffee/nuxt.config.js +++ b/examples/with-coffee/nuxt.config.js @@ -20,8 +20,10 @@ module.exports = { /* ** Build configuration */ + extensions: ['coffee'], build: { extend (config, ctx) { + config.resolve.extensions.push('.ts') config.module.rules.push({ test: /\.coffee$/, loader: 'coffee-loader'