diff --git a/.babelrc b/.babelrc index 3ed94dff9..dc52269c8 100644 --- a/.babelrc +++ b/.babelrc @@ -1,5 +1,5 @@ { "presets": [ - ["env", { "modules": false }] + ["env", { "targets": { "node": 7 }, "modules": false }] ] } diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 000000000..15241dd62 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,4 @@ +{ + "root": true, + "extends": ["plugin:vue-libs/recommended"] +} diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index b31f02096..000000000 --- a/.eslintrc.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - root: true, - extends: ['plugin:vue-libs/recommended'], - rules: { - indent: 'off', - 'space-before-function-paren': 'off' - } -} diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 6313b56c5..000000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -* text=auto eol=lf diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 0a3ad19f4..000000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: 'ci' -on: - push: - branches: - - master - pull_request: - branches: - - master -jobs: - unit-test: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: - - ubuntu-latest - - macos-latest - - windows-latest - fail-fast: false - name: "Unit Test: ${{ matrix.os }}" - steps: - - uses: actions/checkout@v2 - - - name: Install pnpm - uses: pnpm/action-setup@v2 - with: - version: 8 - - - name: Set node version to 16 - uses: actions/setup-node@v2 - with: - node-version: 16 - cache: 'pnpm' - - - run: pnpm install - - - name: Run unit tests - run: pnpm run test - - - name: Set up webpack 5 tests - run: npx json -f package.json -I -e "this.resolutions = {}, this.resolutions.webpack = '^5.0.0', this.devDependencies.webpack = '^5.0.0' " - - - name: Install webpack 5 - run: pnpm install --no-frozen-lockfile - - - name: Run unit tests for webpack 5 - run: pnpm run test && pnpm run test:match-resource diff --git a/.gitignore b/.gitignore index 914a2dab2..e45d3c71e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,7 @@ -.idea -.DS_Store -exploration node_modules -*.log -example/dist -docs/.vuepress/dist -test/.cache -.vscode -TODOS +npm-debug.log +test/output +docs/_book +.DS_Store +.idea +*.iml diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 6e52da593..000000000 --- a/.npmignore +++ /dev/null @@ -1,10 +0,0 @@ -example -test -*.yml -*.log -yarn.lock -tsconfig.json -docs -.github -.vscode -TODOS diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 4b1b4d60d..000000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,762 +0,0 @@ - -# [15.11.1](https://github.com/vuejs/vue-loader/compare/v15.11.0...v15.11.1) (2023-10-18) - -### Bug Fixes - -* fix: fix read property error for accessing lang of script ([#2060](https://github.com/vuejs/vue-loader/pull/2060)) - - - -# [15.11.0](https://github.com/vuejs/vue-loader/compare/v15.10.2...v15.11.0) (2023-10-18) - -### Features - -* A new `experimentalInlineMatchResource` option (webpack 5 only), which leverages webpack 5's [inline matchResource](https://webpack.js.org/api/loaders/#inline-matchresource) feature in the underlying implementation, and works well with the [`experiments.css`](https://webpack.js.org/configuration/experiments/#experimentscss) feature. This also makes `vue-loader` compatible with [Rspack](https://www.rspack.dev/guide/vue). ([#2058](https://github.com/vuejs/vue-loader/pull/2058)) - - - -# [15.10.2](https://github.com/vuejs/vue-loader/compare/v15.10.1...v15.10.2) (2023-08-23) - -### Bug Fixes - -* don't enable prettify by default if prettier 3 is detected ([aa2558d](https://github.com/vuejs/vue-loader/commit/aa2558d)) - - - -# [15.10.1](https://github.com/vuejs/vue-loader/compare/v15.10.0...v15.10.1) (2022-11-14) - -### Bug Fixes - -* skip thread-loader when cloning js rules to template compilation pipeline, fixes ([fb6ff6e](https://github.com/vuejs/vue-loader/commit/fb6ff6e)) - - - -# [15.10.0](https://github.com/vuejs/vue-loader/compare/v15.10.0-beta.6...v15.10.0) (2022-07-01) - - - - -# [15.10.0-beta.6](https://github.com/vuejs/vue-loader/compare/v15.10.0-beta.5...v15.10.0-beta.6) (2022-06-20) - - -### Bug Fixes - -* always pass id to stylePostLoader when possible ([364ad09](https://github.com/vuejs/vue-loader/commit/364ad09)) - - - - -# [15.10.0-beta.5](https://github.com/vuejs/vue-loader/compare/v15.10.0-beta.4...v15.10.0-beta.5) (2022-06-20) - - -### Bug Fixes - -* css v-bind in production mode ([655e5f8](https://github.com/vuejs/vue-loader/commit/655e5f8)) - - - - -# [15.10.0-beta.4](https://github.com/vuejs/vue-loader/compare/v15.10.0-beta.3...v15.10.0-beta.4) (2022-06-20) - - -### Features - -* support css v-bind (requires 2.7.0-beta.3) ([d653f3b](https://github.com/vuejs/vue-loader/commit/d653f3b)) - - - - -# [15.10.0-beta.3](https://github.com/vuejs/vue-loader/compare/v15.10.0-beta.2...v15.10.0-beta.3) (2022-06-16) - - -### Bug Fixes - -* cache descriptor with correct resource path ([f6c83b5](https://github.com/vuejs/vue-loader/commit/f6c83b5)) - - - - -# [15.10.0-beta.2](https://github.com/vuejs/vue-loader/compare/v15.10.0-beta.1...v15.10.0-beta.2) (2022-06-16) - - -### Features - -* use script-analyzed bindings when compiling template ([55de28c](https://github.com/vuejs/vue-loader/commit/55de28c)) - - - - -# [15.10.0-beta.1](https://github.com/vuejs/vue-loader/compare/v15.9.8...v15.10.0-beta.1) (2022-06-14) - - -### Features - -* apply js loaders to compiled template code when used with 2.7 ([30464a8](https://github.com/vuejs/vue-loader/commit/30464a8)) -* compat for vue 2.7, support ` - - +``` js +npm install -g vue-cli +vue init webpack-simple hello +cd hello +npm install +npm run dev ``` -There are many cool features provided by `vue-loader`: - -- Allows using other webpack loaders for each part of a Vue component, for example Sass for ` -``` - -There are many cool features provided by `vue-loader`: - -- 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-loader', + 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 + +> Requires 11.3.0+ + +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-loader', + 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 new file mode 100644 index 000000000..457b923d9 --- /dev/null +++ b/docs/en/configurations/extract-css.md @@ -0,0 +1,104 @@ +# Extracting CSS into a Single File + +``` 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") + +module.exports = { + // other options... + module: { + rules: [ + { + test: /\.vue$/, + loader: 'vue-loader', + options: { + extractCSS: true + } + } + ] + }, + plugins: [ + new ExtractTextPlugin("style.css") + ] +} +``` + +The above will automatically handle extraction for ` +``` + +Under the hood, the text content inside the ` +``` + +However, note this makes your Vue component webpack-specific and not compatible with Browserify and [vueify](https://github.com/vuejs/vueify). **If you intend to ship your Vue component as a reusable 3rd-party component, avoid using this syntax.** diff --git a/docs/en/features/css-modules.md b/docs/en/features/css-modules.md new file mode 100644 index 000000000..af9fb3d66 --- /dev/null +++ b/docs/en/features/css-modules.md @@ -0,0 +1,117 @@ +# CSS Modules + +> requires ^9.8.0 + +[CSS Modules](https://github.com/css-modules/css-modules) is a popular system for modularizing and composing CSS. `vue-loader` provides first-class integration with CSS Modules as an alternative for simulated scoped CSS. + +### Usage + +Just add the `module` attribute to your ` +``` + +This will turn on CSS Modules mode for `css-loader`, and the resulting class identifier object will be injected into the component as a computed property with the name `$style`. You can use it in your templates with a dynamic class binding: + +``` html + +``` + +Since it's a computed property, it also works with the object/array syntax of `:class`: + +``` html + +``` + +And you can also access it from JavaScript: + +``` html + +``` + +Refer to the [CSS Modules spec](https://github.com/css-modules/css-modules) for mode details such as [global exceptions](https://github.com/css-modules/css-modules#exceptions) and [composition](https://github.com/css-modules/css-modules#composition). + +### Custom Inject Name + +You can have more than one ` + + +``` + +### Configuring `css-loader` Query + +CSS Modules are processed via [css-loader](https://github.com/webpack/css-loader). With ` ``` -## Child Component Root Elements +### Child Component Root Elements With `scoped`, the parent component's styles will not leak into child components. However, a child component's root node will be affected by both the parent's scoped CSS and the child's scoped CSS. This is by design so that the parent can style the child root element for layout purposes. -## Deep Selectors +### Deep Selectors If you want a selector in `scoped` styles to be "deep", i.e. affecting child components, you can use the `>>>` combinator: @@ -62,26 +64,14 @@ The above will be compiled into: .a[data-v-f3f3eg9] .b { /* ... */ } ``` -Some pre-processors, such as Sass, may not be able to parse `>>>` properly. In those cases you can use the `/deep/` or `::v-deep` combinator instead - both are aliases for `>>>` and work exactly the same. Based on the example above these two expressions will be compiled to the same output: - -``` html - -``` - -``` html - -``` +Some pre-processors, such as SASS, may not be able to parse `>>>` properly. In those cases you can use the `/deep/` combinator instead - it's an alias for `>>>` and works exactly the same. -## Dynamically Generated Content +### Dynamically Generated Content DOM content created with `v-html` are not affected by scoped styles, but you can still style them using deep selectors. -## Also Keep in Mind +### Also Keep in Mind -- **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. +- **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](https://stevesouders.com/efws/css-selectors/csscreate.php) where you can test the differences yourself. - **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. diff --git a/docs/en/options.md b/docs/en/options.md new file mode 100644 index 000000000..635ec0e95 --- /dev/null +++ b/docs/en/options.md @@ -0,0 +1,323 @@ +# Options Reference + +## Usage Difference Between webpack 1 & 2 + +For webpack 2: pass the options directly to the loader rule. + +``` js +module.exports = { + // ... + module: { + rules: [ + { + test: /\.vue$/, + loader: 'vue-loader', + options: { + // `vue-loader` options + } + } + ] + } +} +``` + +For webpack 1.x: add a root `vue` block in your webpack config. + +``` js +module.exports = { + // ... + vue: { + // `vue-loader` options + } +} +``` + +### loaders + +- type: `{ [lang: string]: string }` + + 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: + + - `