diff --git a/.circleci/config.yml b/.circleci/config.yml index ed4cf0c85..94ade40f7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,3 +23,4 @@ jobs: - run: yarn lint - run: yarn test + - run: yarn test:webpack5 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..b4d5945c5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,34 @@ +name: 'ci' +on: + push: + branches: + - '**' + pull_request: + branches: + - next +jobs: + test-webpack4: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set node version to 16 + uses: actions/setup-node@v2 + with: + node-version: 16 + cache: 'yarn' + - run: yarn install + - run: yarn lint + - run: yarn test + + test-webpack5: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set node version to 16 + uses: actions/setup-node@v2 + with: + node-version: 16 + cache: 'yarn' + - run: yarn install + - run: yarn build + - run: yarn test:webpack5 diff --git a/.gitignore b/.gitignore index a7cb4c488..7ff6b0d08 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,9 @@ .DS_Store node_modules dist +dist-ssr link.sh .cache TODOs.md +coverage +.vscode diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..af0c0b14c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,370 @@ +## [16.8.2](https://github.com/vuejs/vue-loader/compare/v16.8.1...v16.8.2) (2021-10-26) + + +### Bug Fixes + +* should allow chaining with loaders for non-vue files ([#1889](https://github.com/vuejs/vue-loader/issues/1889)) ([f32f953](https://github.com/vuejs/vue-loader/commit/f32f9538ea34fc08e1a28622227896241847690f)), closes [#1879](https://github.com/vuejs/vue-loader/issues/1879) [#1883](https://github.com/vuejs/vue-loader/issues/1883) [#1890](https://github.com/vuejs/vue-loader/issues/1890) +* **plugin:** use compiler.webpack when possible ([#1884](https://github.com/vuejs/vue-loader/issues/1884)) ([820d23c](https://github.com/vuejs/vue-loader/commit/820d23cbf16013dae894e0d84ed9da6e58a37584)) + + + +## [16.8.1](https://github.com/vuejs/vue-loader/compare/v16.8.0...v16.8.1) (2021-09-22) + + +### Bug Fixes + +* fix template options resolving for ts ([91f581b](https://github.com/vuejs/vue-loader/commit/91f581b99644119b68e586a0b642fff3811c8741)) + +# [16.8.0](https://github.com/vuejs/vue-loader/compare/v16.7.1...v16.8.0) (2021-09-22) + + +### Bug Fixes + +* **hmr:** fix hmr regression ([bacc6a9](https://github.com/vuejs/vue-loader/commit/bacc6a9eeca40d6028a2d9a5f6ee02e6c8574abd)) + + +### Features + +* enableTsInTemplate option ([7613534](https://github.com/vuejs/vue-loader/commit/7613534954b83489a060860b9525a0d121023c5b)) + + - When used with `ts-loader`, due to `ts-loader`'s cache invalidation behavior, it sometimes prevents the template from being hot-reloaded in isolation, causing the component to reload despite only the template being edited. If this is annoying, you can set this option to `false` (and avoid using TS expressions in templates). + + - Alternatively, leave this option on (by default) and use [`esbuild-loader`](https://github.com/privatenumber/esbuild-loader) to transpile TS instead, which doesn't suffer from this problem (it's also a lot faster). However, do note you will need to rely on TS type checking from other sources (e.g. IDE or `vue-tsc`). + +## [16.7.1](https://github.com/vuejs/vue-loader/compare/v16.7.0...v16.7.1) (2021-09-22) + + +### Bug Fixes + +* remove pure annotation for custom blocks ([cd891e5](https://github.com/vuejs/vue-loader/commit/cd891e593bf7f8aff852f1d47fda2337de661bea)) + + +# [16.7.0](https://github.com/vuejs/vue-loader/compare/v16.6.0...v16.7.0) (2021-09-21) + + +### Features + +* support optional @vue/compiler-sfc peer dep ([21725a4](https://github.com/vuejs/vue-loader/commit/21725a4ebc9c8d7f8a590d700017759327e21c2e)) + + +# [16.6.0](https://github.com/vuejs/vue-loader/compare/v16.5.0...v16.6.0) (2021-09-20) + + +### Bug Fixes + +* generate treeshaking friendly code ([11e3cb8](https://github.com/vuejs/vue-loader/commit/11e3cb8a8a4a4e0aedc2978ce6d7e549a61de3d7)) + + +### Features + +* support ts in template expressions ([573fbd2](https://github.com/vuejs/vue-loader/commit/573fbd2e72c3246c2daadb8d8c053464c964cfe3)) + + +# [16.5.0](https://github.com/vuejs/vue-loader/compare/v16.4.1...v16.5.0) (2021-08-07) + +* Custom Elements mode behavior changed: now only inlines the CSS and no longer exports the custom element constructor (exports the component as in normal mode). Users now need to explicitly call `defineCustomElement` on the component. This allows the custom element to be defined using an async version of the source component. + + +## [16.4.1](https://github.com/vuejs/vue-loader/compare/v16.4.0...v16.4.1) (2021-08-02) + + +### Bug Fixes + +* fix webpack 5.48 compatibility ([b94289c](https://github.com/vuejs/vue-loader/commit/b94289c9fb395556100ec121529dfe676280d3cd)), closes [#1859](https://github.com/vuejs/vue-loader/issues/1859) + + +# [16.4.0](https://github.com/vuejs/vue-loader/compare/v16.3.3...v16.4.0) (2021-07-30) + + +### Features + +* customElement option support for Vue 3.2 ([e19fcda](https://github.com/vuejs/vue-loader/commit/e19fcdaa62c4aa5d826c33a0e7fb8786904ee225)) + + +## [16.3.3](https://github.com/vuejs/vue-loader/compare/v16.3.2...v16.3.3) (2021-07-21) + + +### Bug Fixes + +* mark @vue/compiler-sfc as an optional peer dependency ([089473a](https://github.com/vuejs/vue-loader/commit/089473af97077b8e14b3feff48d32d2733ad792c)) + + + +## [16.3.2](https://github.com/vuejs/vue-loader/compare/v16.3.1...v16.3.2) (2021-07-20) + + +### Bug Fixes + +* add undeclared peer dependency `webpack` and `@vue/compiler-sfc` ([#1853](https://github.com/vuejs/vue-loader/issues/1853)) ([330d672](https://github.com/vuejs/vue-loader/commit/330d672fb344fddefec98e170587d93876a9e354)) + + + +## [16.3.1](https://github.com/vuejs/vue-loader/compare/v16.3.0...v16.3.1) (2021-07-16) + + +### Bug Fixes + +* pick up production env in thread-loader context ([821a3a3](https://github.com/vuejs/vue-loader/commit/821a3a35f04cda3154a9341898225f61d72b3f05)), closes [vuejs/vue-next#3921](https://github.com/vuejs/vue-next/issues/3921) + + + +# [16.3.0](https://github.com/vuejs/vue-loader/compare/v16.2.0...v16.3.0) (2021-06-29) + + +### Features + +* pass on compilerOptions and refSugar when using ` @@ -46,72 +61,72 @@ In a nutshell, the combination of webpack and `vue-loader` gives you a modern, f `vue-loader` is not a simple source transform loader. It handles each language blocks inside an SFC with its own dedicated loader chain (you can think of each block as a "virtual module"), and finally assembles the blocks together into the final module. Here's a brief overview of how the whole thing works: -1. `vue-loader` parses the SFC source code into an *SFC Descriptor* using `@vue/compiler-sfc`. It then generates an import for each language block so the actual returned module code looks like this: +1. `vue-loader` parses the SFC source code into an _SFC Descriptor_ using `@vue/compiler-sfc`. It then generates an import for each language block so the actual returned module code looks like this: - ``` js - // code returned from the main loader for 'source.vue' + ```js + // code returned from the main loader for 'source.vue' - // import the + + diff --git a/test/fixtures/script-import.js b/test/fixtures/script-import.js new file mode 100644 index 000000000..ce0b6a81c --- /dev/null +++ b/test/fixtures/script-import.js @@ -0,0 +1,7 @@ +export default { + data() { + return { + msg: 'Hello from Component A!', + } + }, +} diff --git a/test/fixtures/script-import.vue b/test/fixtures/script-import.vue new file mode 100644 index 000000000..08f329768 --- /dev/null +++ b/test/fixtures/script-import.vue @@ -0,0 +1 @@ + diff --git a/test/fixtures/style-import-scoped.css b/test/fixtures/style-import-scoped.css new file mode 100644 index 000000000..954b5d865 --- /dev/null +++ b/test/fixtures/style-import-scoped.css @@ -0,0 +1 @@ +h1 { color: green; } diff --git a/test/fixtures/style-import-twice-sub.vue b/test/fixtures/style-import-twice-sub.vue new file mode 100644 index 000000000..6ae3d7173 --- /dev/null +++ b/test/fixtures/style-import-twice-sub.vue @@ -0,0 +1,3 @@ + + + diff --git a/test/fixtures/style-import-twice.vue b/test/fixtures/style-import-twice.vue new file mode 100644 index 000000000..1459b47e0 --- /dev/null +++ b/test/fixtures/style-import-twice.vue @@ -0,0 +1,9 @@ + + + + diff --git a/test/fixtures/style-import.css b/test/fixtures/style-import.css new file mode 100644 index 000000000..5ce768ca5 --- /dev/null +++ b/test/fixtures/style-import.css @@ -0,0 +1 @@ +h1 { color: red; } diff --git a/test/fixtures/style-import.vue b/test/fixtures/style-import.vue new file mode 100644 index 000000000..54b83bf89 --- /dev/null +++ b/test/fixtures/style-import.vue @@ -0,0 +1,2 @@ + + diff --git a/test/fixtures/template-import-pre.vue b/test/fixtures/template-import-pre.vue new file mode 100644 index 000000000..461624104 --- /dev/null +++ b/test/fixtures/template-import-pre.vue @@ -0,0 +1 @@ + diff --git a/test/fixtures/template-import.html b/test/fixtures/template-import.html new file mode 100644 index 000000000..c9dc2eef3 --- /dev/null +++ b/test/fixtures/template-import.html @@ -0,0 +1,3 @@ +
+

hello

+
diff --git a/test/fixtures/template-import.pug b/test/fixtures/template-import.pug new file mode 100644 index 000000000..bc60abffa --- /dev/null +++ b/test/fixtures/template-import.pug @@ -0,0 +1,2 @@ +div + h1 hello diff --git a/test/fixtures/template-import.vue b/test/fixtures/template-import.vue new file mode 100644 index 000000000..00de859d2 --- /dev/null +++ b/test/fixtures/template-import.vue @@ -0,0 +1 @@ + diff --git a/test/fixtures/ts.vue b/test/fixtures/ts.vue new file mode 100644 index 000000000..95031a7f2 --- /dev/null +++ b/test/fixtures/ts.vue @@ -0,0 +1,11 @@ + + + + + diff --git a/test/fixtures/unit-test.js b/test/fixtures/unit-test.js new file mode 100644 index 000000000..70d411983 --- /dev/null +++ b/test/fixtures/unit-test.js @@ -0,0 +1,5 @@ +describe('example', () => { + it('basic', (done) => { + done() + }) +}) diff --git a/test/mock-loaders/docs.js b/test/mock-loaders/docs.js new file mode 100644 index 000000000..c79cd45c0 --- /dev/null +++ b/test/mock-loaders/docs.js @@ -0,0 +1,9 @@ +module.exports = function (source, map) { + this.callback( + null, + `export default Component => { + Component.__docs = ${JSON.stringify(source)} + }`, + map + ) +} diff --git a/test/mock-loaders/html.js b/test/mock-loaders/html.js new file mode 100644 index 000000000..182d66e49 --- /dev/null +++ b/test/mock-loaders/html.js @@ -0,0 +1,3 @@ +module.exports = function (content) { + return content.replace(/red/, 'green') +} diff --git a/test/mock-loaders/js.js b/test/mock-loaders/js.js new file mode 100644 index 000000000..a0c719bb1 --- /dev/null +++ b/test/mock-loaders/js.js @@ -0,0 +1,3 @@ +module.exports = function (content) { + return content.replace(/Hello from Component A!/, 'Changed!') +} diff --git a/test/mock-loaders/query.js b/test/mock-loaders/query.js new file mode 100644 index 000000000..0a2ff8727 --- /dev/null +++ b/test/mock-loaders/query.js @@ -0,0 +1,22 @@ +module.exports = function (content) { + const query = this.resourceQuery.slice(1) + + if (/change/.test(query)) { + return ` + + + ` + } + + return content +} diff --git a/test/script.spec.ts b/test/script.spec.ts new file mode 100644 index 000000000..f2405c66b --- /dev/null +++ b/test/script.spec.ts @@ -0,0 +1,13 @@ +import { mockBundleAndRun } from './utils' + +test('named exports', async () => { + const { exports } = await mockBundleAndRun({ + entry: 'named-exports.vue', + }) + expect(exports.default.name).toBe('named-exports') + expect(exports.foo()).toBe(1) +}) + +test('experimental