diff --git a/.babelrc b/.babelrc index c13c5f6..dc52269 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,5 @@ { - "presets": ["es2015"] + "presets": [ + ["env", { "targets": { "node": 7 }, "modules": false }] + ] } diff --git a/.eslintrc b/.eslintrc index d0dd64c..15241dd 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,4 +1,4 @@ { "root": true, - "extends": "vue" + "extends": ["plugin:vue-libs/recommended"] } diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..bd0e4f2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,7 @@ + diff --git a/.gitignore b/.gitignore index e45d3c7..44a66dd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ docs/_book .DS_Store .idea *.iml +yarn.lock diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..44a66dd --- /dev/null +++ b/.npmignore @@ -0,0 +1,8 @@ +node_modules +npm-debug.log +test/output +docs/_book +.DS_Store +.idea +*.iml +yarn.lock diff --git a/LICENSE b/LICENSE index 2c8fd99..34516e3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Q42 +Copyright (c) 2018-present, 美团点评 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -9,14 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 3e5a37f..e13d7c7 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,9 @@ -# vue-loader [![Build Status](https://circleci.com/gh/vuejs/vue-loader/tree/master.svg?style=shield)](https://circleci.com/gh/vuejs/vue-loader/tree/master) [![npm package](https://img.shields.io/npm/v/vue-loader.svg?maxAge=2592000)](https://www.npmjs.com/package/vue-loader) +# mpvue-loader -> Vue.js component loader for [Webpack](http://webpack.github.io). +>Webpack loader for mpvue components -**NOTE: the master branch (9.0+) only works with Vue 2.x. For usage with Vue 1.x, see the [8.x branch](https://github.com/vuejs/vue-loader/tree/8.x).** +本仓库是 fork 自 [vue-loader](https://github.com/vuejs/vue-loader) 修改而来,主要为 webpack 打包 mpvue components 提供能力。 -It allows you to write your components in this format: +更多详细文档请查阅 [mpvue-loader](http://mpvue.com/build/mpvue-loader)。 -![screenshot](http://blog.evanyou.me/images/vue-component.png) - -The best way to get started is with [vue-cli](https://github.com/vuejs/vue-cli): - -``` js -npm install -g vue-cli -vue init webpack-simple hello -cd hello -npm install -npm run dev -``` - -This will setup a basic Webpack + `vue-loader` project for you, with `*.vue` files and hot-reloading working out of the box! - -For advanced `vue-loader` configuration, checkout the [documentation](http://vuejs.github.io/vue-loader/). +bug 或者交流建议等请反馈到 [mpvue/issues](https://github.com/Meituan-Dianping/mpvue/issues)。 diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..5cf1f0e --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,21 @@ +# Test against the latest version of this Node.js version +environment: + nodejs_version: "6" + +# Install scripts. (runs after repo cloning) +install: + # Get the latest stable version of Node.js or io.js + - ps: Install-Product node $env:nodejs_version + # install modules + - npm install + +# Post-install test scripts. +test_script: + # Output useful info for debugging. + - node --version + - npm --version + # run tests + - npm test + +# Don't actually build. +build: off diff --git a/docs/LANGS.md b/docs/LANGS.md index 00ad892..e8bff3d 100644 --- a/docs/LANGS.md +++ b/docs/LANGS.md @@ -1,2 +1,6 @@ * [English](en/) -* [한국어](ko/) +* [한국어](kr/) +* [Русский](ru/) +* [Português](pt_BR/) +* [日本語](ja/) +* [中文](zh-cn/) diff --git a/docs/book.json b/docs/book.json index 76d4871..1021899 100644 --- a/docs/book.json +++ b/docs/book.json @@ -1,6 +1,7 @@ { + "title": "vue-loader", "gitbook": ">3.0.0", - "plugins": ["edit-link", "theme-vuejs@git+https://github.com/pearofducks/gitbook-plugin-theme-vuejs.git", "-fontsettings", "github"], + "plugins": ["edit-link", "theme-vuejs", "-fontsettings", "github"], "pluginsConfig": { "edit-link": { "base": "https://github.com/vuejs/vue-loader/tree/master/docs", diff --git a/docs/en/README.md b/docs/en/README.md index 2bb3116..ed4480e 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -10,6 +10,7 @@ There are many cool features provided by `vue-loader`: - ES2015 enabled by default; - Allows using other Webpack loaders for each part of a Vue component, for example SASS for ` +``` + +#### webpack.config.js + +``` js +// Webpack 2.x +var ExtractTextPlugin = require("extract-text-webpack-plugin") + +module.exports = { + module: { + rules: [ + { + test: /\.vue$/, + loader: 'vue', + options: { + loaders: { + // extract all content as raw text + 'docs': ExtractTextPlugin.extract('raw-loader'), + } + } + } + ] + }, + plugins: [ + // output all docs into a single file + new ExtractTextPlugin('docs.md') + ] +} +``` + +## Runtime available docs + +Here's an example of injecting the `` custom blocks into the component so that it's available during runtime. + +#### docs-loader.js + +In order for the custom block content to be injected, we'll need a custom loader: + +``` js +module.exports = function (source, map) { + this.callback(null, 'module.exports = function(Component) {Component.options.__docs = ' + + JSON.stringify(source) + + '}', map) +} +``` + +#### webpack.config.js + +Now we'll configure webpack to use our custom loader for `` custom blocks. + +``` js +const docsLoader = require.resolve('./custom-loaders/docs-loader.js') + +module.exports = { + module: { + rules: [ + { + test: /\.vue$/, + loader: 'vue', + options: { + loaders: { + 'docs': docsLoader + } + } + } + ] + } +} +``` + +#### component.vue + +We are now able to access the `` block's content of imported components during runtime. + +``` html + + + +``` diff --git a/docs/en/configurations/extract-css.md b/docs/en/configurations/extract-css.md index b0701a0..f40b2c0 100644 --- a/docs/en/configurations/extract-css.md +++ b/docs/en/configurations/extract-css.md @@ -1,13 +1,13 @@ # Extracting CSS into a Single File -Example config to extract all the processed CSS in all Vue components into a single CSS file: - -### Webpack 1.x - ``` bash npm install extract-text-webpack-plugin --save-dev ``` +## The Easy Way + +> requires vue-loader@^12.0.0 and webpack@^2.0.0 + ``` js // webpack.config.js var ExtractTextPlugin = require("extract-text-webpack-plugin") @@ -15,31 +15,32 @@ var ExtractTextPlugin = require("extract-text-webpack-plugin") module.exports = { // other options... module: { - loaders: [ + rules: [ { test: /\.vue$/, - loader: 'vue' - }, + loader: 'vue-loader', + options: { + extractCSS: true + } + } ] }, - vue: { - loaders: { - css: ExtractTextPlugin.extract("css"), - // you can also include ``` @@ -49,3 +49,19 @@ Into the following: 4. **Scoped styles do not eliminate the need for classes**. Due to the way browsers render various CSS selectors, `p { color: red }` will be many times slower when scoped (i.e. when combined with an attribute selector). If you use classes or ids instead, such as in `.example { color: red }`, then you virtually eliminate that performance hit. [Here's a playground](http://stevesouders.com/efws/css-selectors/csscreate.php) where you can test the differences yourself. 5. **Be careful with descendant selectors in recursive components!** For a CSS rule with the selector `.a .b`, if the element that matches `.a` contains a recursive child component, then all `.b` in that child component will be matched by the rule. + +6. If you need nested selectors in `scoped` styles, you will have to use `>>>` operator for CSS and `/deep/` for `scss`: + + ``` html + + + + ``` diff --git a/docs/en/options.md b/docs/en/options.md index 6789e7c..09e6168 100644 --- a/docs/en/options.md +++ b/docs/en/options.md @@ -2,18 +2,7 @@ ## Usage Difference Between Webpack 1 & 2 -For Webpack 1.x: add a root `vue` block in your Webpack config: - -``` js -module.exports = { - // ... - vue: { - // vue-loader options - } -} -``` - -For Webpack 2 (^2.1.0-beta.25): +For Webpack 2: pass the options directly to the loader rule. ``` js module.exports = { @@ -22,7 +11,7 @@ module.exports = { rules: [ { test: /\.vue$/, - loader: 'vue', + loader: 'vue-loader', options: { // vue-loader options } @@ -32,11 +21,22 @@ module.exports = { } ``` +For Webpack 1.x: add a root `vue` block in your Webpack config. + +``` js +module.exports = { + // ... + vue: { + // vue-loader options + } +} +``` + ### loaders -- type: `Object` +- type: `{ [lang: string]: string }` - An object specifying Webpack loaders to use for language blocks inside `*.vue` files. The key corresponds to the `lang` attribute for language blocks, if specified. The default `lang` for each type is: + An object specifying Webpack loaders to overwrite the default loaders used for language blocks inside `*.vue` files. The key corresponds to the `lang` attribute for language blocks, if specified. The default `lang` for each type is: - `