)/, `$1${html}`)
- )
-})
diff --git a/example/types.ts b/example/types.ts
deleted file mode 100644
index 1de15a3db..000000000
--- a/example/types.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-export interface Props {
- msg: string
- lol?: string
-}
diff --git a/example/webpack.config.js b/example/webpack.config.js
deleted file mode 100644
index c240ad021..000000000
--- a/example/webpack.config.js
+++ /dev/null
@@ -1,138 +0,0 @@
-const path = require('path')
-const webpack = require('webpack')
-const VueLoaderPlugin = require('../dist/plugin').default
-const MiniCssExtractPlugin = require('mini-css-extract-plugin')
-
-module.exports = (env = {}) => {
- const isProd = env.prod
- const isSSR = env.ssr
-
- /**
- * Some notes regarding config for the server build of an SSR app:
- * 1. target: 'node'
- * 2. output.libraryTarget: 'commonjs' (so the exported app can be required)
- * 3. externals: this is mostly for faster builds.
- * - externalize @vue/* deps via commonjs require()
- * - externalize client side deps that are never used on the server, e.g.
- * ones that are only used in onMounted() to empty modules
- * 4. If using cache-loader or any other forms of cache, make sure the cache
- * key takes client vs. server builds into account!
- */
- const genConfig = (isServerBuild = false) => {
- const minimize = isProd && !isServerBuild && !env.noMinimize
-
- return {
- mode: isProd ? 'production' : 'development',
- entry: path.resolve(__dirname, './main.js'),
- target: isServerBuild ? 'node' : 'web',
- devtool: 'source-map',
- resolve: {
- extensions: ['.js', '.ts'],
- alias: process.env.WEBPACK4
- ? {
- webpack: 'webpack4',
- }
- : {},
- },
- output: {
- path: path.resolve(
- __dirname,
- isSSR ? (isServerBuild ? 'dist-ssr/server' : 'dist-ssr/dist') : 'dist'
- ),
- filename: '[name].js',
- publicPath: '/dist/',
- libraryTarget: isServerBuild ? 'commonjs' : undefined,
- },
- externals: isServerBuild
- ? [
- (ctx, request, cb) => {
- if (/^@vue/.test(request)) {
- return cb(null, 'commonjs ' + request)
- }
- cb()
- },
- ]
- : undefined,
- module: {
- rules: [
- {
- test: /\.vue$/,
- loader: 'vue-loader',
- options: {
- // reactivityTransform: true,
- compilerOptions: {
- isCustomElement: (tag) => tag.startsWith('custom-'),
- },
- },
- },
- {
- test: /\.png$/,
- use: [
- {
- loader: 'url-loader',
- options: {
- limit: 8192,
- },
- },
- ],
- },
- {
- test: /\.css$/,
- use: [MiniCssExtractPlugin.loader, 'css-loader'],
- },
- {
- test: /\.ts$/,
- use: [
- {
- loader: process.env.WEBPACK4
- ? require.resolve('ts-loader')
- : require.resolve('ts-loader-v9'),
- options: {
- transpileOnly: true,
- appendTsSuffixTo: [/\.vue$/],
- },
- },
- ],
- },
- // target
custom blocks
- {
- resourceQuery: /blockType=docs/,
- loader: require.resolve('./docs-loader'),
- },
- ],
- },
- plugins: [
- new VueLoaderPlugin(),
- new MiniCssExtractPlugin({
- filename: '[name].css',
- }),
- new webpack.DefinePlugin({
- __IS_SSR__: !!isSSR,
- __VUE_OPTIONS_API__: true,
- __VUE_PROD_DEVTOOLS__: false,
- __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false,
- }),
- ],
- optimization: {
- minimize,
- },
- devServer: {
- hot: true,
- stats: 'minimal',
- contentBase: __dirname,
- overlay: true,
- },
- resolveLoader: {
- alias: {
- 'vue-loader': require.resolve('../'),
- },
- },
- }
- }
-
- if (!isSSR) {
- return genConfig()
- } else {
- return [genConfig(), genConfig(true)]
- }
-}
diff --git a/index.js b/index.js
new file mode 100644
index 000000000..18abae36c
--- /dev/null
+++ b/index.js
@@ -0,0 +1 @@
+module.exports = require('./lib/loader')
diff --git a/jest.config.js b/jest.config.js
deleted file mode 100644
index fc6d1b325..000000000
--- a/jest.config.js
+++ /dev/null
@@ -1,27 +0,0 @@
-const isWebpack4 = process.env.WEBPACK4
-
-console.log(
- `running tests with webpack ${isWebpack4 ? '4' : '5'}${
- !isWebpack4 && process.env.INLINE_MATCH_RESOURCE
- ? ' with inline match resource enabled'
- : ''
- }...`
-)
-
-module.exports = {
- preset: 'ts-jest',
- testTimeout: 60000,
- testEnvironment: 'node',
- testPathIgnorePatterns: ['/dist/', '/node_modules/'],
- globals: {
- 'ts-jest': {
- diagnostics: false,
- },
- },
- moduleNameMapper: process.env.WEBPACK4
- ? {
- '^webpack$': 'webpack4',
- '^webpack/(.*)': 'webpack4/$1',
- }
- : undefined,
-}
diff --git a/lib/helpers.js b/lib/helpers.js
new file mode 100644
index 000000000..4e922c375
--- /dev/null
+++ b/lib/helpers.js
@@ -0,0 +1,409 @@
+const querystring = require('querystring')
+const loaderUtils = require('loader-utils')
+const normalize = require('./utils/normalize')
+const tryRequire = require('./utils/try-require')
+const styleCompilerPath = normalize.lib('style-compiler/index')
+
+// internal lib loaders
+const selectorPath = normalize.lib('selector')
+const templateCompilerPath = normalize.lib('template-compiler/index')
+const templatePreprocessorPath = normalize.lib('template-compiler/preprocessor')
+
+// dep loaders
+const styleLoaderPath = normalize.dep('vue-style-loader')
+
+// check whether default js loader exists
+const hasBabel = !!tryRequire('babel-loader')
+const hasBuble = !!tryRequire('buble-loader')
+
+const rewriterInjectRE = /\b(css(?:-loader)?(?:\?[^!]+)?)(?:!|$)/
+
+const defaultLang = {
+ template: 'html',
+ styles: 'css',
+ script: 'js'
+}
+
+const postcssExtensions = [
+ 'postcss', 'pcss', 'sugarss', 'sss'
+]
+
+// When extracting parts from the source vue file, we want to apply the
+// loaders chained before vue-loader, but exclude some loaders that simply
+// produces side effects such as linting.
+function getRawRequest (
+ { resource, loaderIndex, loaders },
+ excludedPreLoaders = /eslint-loader/
+) {
+ return loaderUtils.getRemainingRequest({
+ resource: resource,
+ loaderIndex: loaderIndex,
+ loaders: loaders.filter(loader => !excludedPreLoaders.test(loader.path))
+ })
+}
+
+// sass => sass-loader
+// sass-loader => sass-loader
+// sass?indentedSyntax!css => sass-loader?indentedSyntax!css-loader
+function ensureLoader (lang) {
+ return lang
+ .split('!')
+ .map(loader =>
+ loader.replace(
+ /^([\w-]+)(\?.*)?/,
+ (_, name, query) =>
+ (/-loader$/.test(name) ? name : name + '-loader') + (query || '')
+ )
+ )
+ .join('!')
+}
+
+function ensureBang (loader) {
+ if (loader.charAt(loader.length - 1) !== '!') {
+ return loader + '!'
+ } else {
+ return loader
+ }
+}
+
+function resolveLoaders (
+ optionsId,
+ options,
+ moduleId,
+ isProduction,
+ hasScoped,
+ hasComment,
+ hasFunctionalTemplate,
+ needCssSourceMap
+) {
+ let cssLoaderOptions = ''
+ if (needCssSourceMap) {
+ cssLoaderOptions += '?sourceMap'
+ }
+ if (isProduction) {
+ cssLoaderOptions += (cssLoaderOptions ? '&' : '?') + 'minimize'
+ }
+
+ const bubleTemplateOptions = Object.assign({}, options.buble)
+ bubleTemplateOptions.transforms = Object.assign({}, bubleTemplateOptions.transforms)
+ bubleTemplateOptions.transforms.stripWithFunctional = hasFunctionalTemplate
+
+ const bubleOptions = hasBuble && options.buble
+ ? '?' + JSON.stringify(options.buble)
+ : ''
+
+ const templateCompilerOptions =
+ '?' +
+ JSON.stringify({
+ id: moduleId,
+ hasScoped,
+ hasComment,
+ optionsId,
+ buble: bubleTemplateOptions
+ })
+
+ const defaultLoaders = {
+ html: templateCompilerPath + templateCompilerOptions,
+ css: options.extractCSS
+ ? getCSSExtractLoader(null, options, cssLoaderOptions)
+ : styleLoaderPath + '!' + 'css-loader' + cssLoaderOptions,
+ js: hasBuble
+ ? 'buble-loader' + bubleOptions
+ : hasBabel ? 'babel-loader' : ''
+ }
+
+ function getCSSExtractLoader (lang) {
+ let extractor
+ const op = options.extractCSS
+ // extractCSS option is an instance of ExtractTextPlugin
+ if (typeof op.extract === 'function') {
+ extractor = op
+ } else {
+ extractor = tryRequire('extract-text-webpack-plugin')
+ if (!extractor) {
+ throw new Error(
+ '[vue-loader] extractCSS: true requires extract-text-webpack-plugin ' +
+ 'as a peer dependency.'
+ )
+ }
+ }
+ const langLoader = lang ? ensureBang(ensureLoader(lang)) : ''
+ return extractor.extract({
+ use: 'css-loader' + cssLoaderOptions + '!' + langLoader,
+ fallback: 'vue-style-loader'
+ })
+ }
+
+ return {
+ defaultLoaders,
+ getCSSExtractLoader,
+ loaders: Object.assign({}, defaultLoaders, options.loaders),
+ preLoaders: options.preLoaders || {},
+ postLoaders: options.postLoaders || {}
+ }
+}
+
+module.exports = function createHelpers (
+ optionsId,
+ loaderContext,
+ options,
+ moduleId,
+ parts,
+ isProduction,
+ hasScoped,
+ hasComment,
+ hasFunctionalTemplate,
+ needCssSourceMap
+) {
+ const rawRequest = getRawRequest(loaderContext, options.excludedPreLoaders)
+
+ const {
+ defaultLoaders,
+ getCSSExtractLoader,
+ loaders,
+ preLoaders,
+ postLoaders
+ } = resolveLoaders(
+ optionsId,
+ options,
+ moduleId,
+ isProduction,
+ hasScoped,
+ hasComment,
+ hasFunctionalTemplate,
+ needCssSourceMap
+ )
+
+ function getRequire (type, part, index, scoped) {
+ return 'require(' + getRequestString(type, part, index, scoped) + ')'
+ }
+
+ function getImport (type, part, index, scoped) {
+ return (
+ 'import __vue_' + type + '__ from ' +
+ getRequestString(type, part, index, scoped)
+ )
+ }
+
+ function getNamedExports (type, part, index, scoped) {
+ return (
+ 'export * from ' +
+ getRequestString(type, part, index, scoped)
+ )
+ }
+
+ function getRequestString (type, part, index, scoped) {
+ return loaderUtils.stringifyRequest(
+ loaderContext,
+ // disable all configuration loaders
+ '!!' +
+ // get loader string for pre-processors
+ getLoaderString(type, part, index, scoped) +
+ // select the corresponding part from the vue file
+ getSelectorString(type, index || 0) +
+ // the url to the actual vue file, including remaining requests
+ rawRequest
+ )
+ }
+
+ function getRequireForSrc (type, impt, scoped) {
+ return 'require(' + getSrcRequestString(type, impt, scoped) + ')'
+ }
+
+ function getImportForSrc (type, impt, scoped) {
+ return (
+ 'import __vue_' + type + '__ from ' +
+ getSrcRequestString(type, impt, scoped)
+ )
+ }
+
+ function getNamedExportsForSrc (type, impt, scoped) {
+ return (
+ 'export * from ' +
+ getSrcRequestString(type, impt, scoped)
+ )
+ }
+
+ function getSrcRequestString (type, impt, scoped) {
+ return loaderUtils.stringifyRequest(
+ loaderContext,
+ '!!' + getLoaderString(type, impt, -1, scoped) + impt.src
+ )
+ }
+
+ function addCssModulesToLoader (loader, part, index) {
+ if (!part.module) return loader
+ const option = options.cssModules || {}
+ const DEFAULT_OPTIONS = {
+ modules: true
+ }
+ const OPTIONS = {
+ localIdentName: '[local]_[hash:base64:8]',
+ importLoaders: 1
+ }
+ return loader.replace(/((?:^|!)css(?:-loader)?)(\?[^!]*)?/, (m, $1, $2) => {
+ // $1: !css-loader
+ // $2: ?a=b
+ const query = loaderUtils.parseQuery($2 || '?')
+ Object.assign(query, OPTIONS, option, DEFAULT_OPTIONS)
+ if (index > 0) {
+ // Note:
+ // Class name is generated according to its filename.
+ // Different
-
-
-
-
-
-
\ No newline at end of file
diff --git a/test/fixtures/css-modules-simple.vue b/test/fixtures/css-modules-simple.vue
deleted file mode 100644
index f677aa29c..000000000
--- a/test/fixtures/css-modules-simple.vue
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
diff --git a/test/fixtures/css-modules.vue b/test/fixtures/css-modules.vue
index 473f90ce9..8646cb868 100644
--- a/test/fixtures/css-modules.vue
+++ b/test/fixtures/css-modules.vue
@@ -10,11 +10,11 @@
}
-
diff --git a/test/fixtures/custom-blocks.vue b/test/fixtures/custom-blocks.vue
new file mode 100644
index 000000000..8e7925aca
--- /dev/null
+++ b/test/fixtures/custom-blocks.vue
@@ -0,0 +1,21 @@
+
+en:
+ hello: "hello world"
+ja:
+ hello: "こんにちは、世界"
+
+
+## foo
+
+
+export default function (Component) {
+ Component.options.foo = 1
+}
+
+
+
+
+
diff --git a/test/fixtures/custom-directive.vue b/test/fixtures/custom-directive.vue
new file mode 100644
index 000000000..b11d74e33
--- /dev/null
+++ b/test/fixtures/custom-directive.vue
@@ -0,0 +1,3 @@
+
+
+
diff --git a/test/fixtures/custom-language.vue b/test/fixtures/custom-language.vue
index f026cd7f1..3684d135b 100644
--- a/test/fixtures/custom-language.vue
+++ b/test/fixtures/custom-language.vue
@@ -1,6 +1,6 @@
-
- describe('example', () => {
- it('basic', done => {
+
+ describe('example', function () {
+ it('basic', function (done) {
done();
})
})
diff --git a/test/fixtures/custom-module.js b/test/fixtures/custom-module.js
new file mode 100644
index 000000000..ff1183412
--- /dev/null
+++ b/test/fixtures/custom-module.js
@@ -0,0 +1,9 @@
+module.exports = [
+ {
+ postTransformNode: el => {
+ if (el.staticClass) {
+ el.staticClass = '"red blue"'
+ }
+ }
+ }
+]
diff --git a/test/fixtures/custom-module.vue b/test/fixtures/custom-module.vue
new file mode 100644
index 000000000..fd9dbe526
--- /dev/null
+++ b/test/fixtures/custom-module.vue
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/test/fixtures/custom-options.vue b/test/fixtures/custom-options.vue
new file mode 100644
index 000000000..c8249bbd6
--- /dev/null
+++ b/test/fixtures/custom-options.vue
@@ -0,0 +1,7 @@
+
+ describe('example', function () {
+ it('basic', function (done) {
+ done();
+ })
+ })
+
diff --git a/test/fixtures/custom-query.vue b/test/fixtures/custom-query.vue
deleted file mode 100644
index 675d275f4..000000000
--- a/test/fixtures/custom-query.vue
+++ /dev/null
@@ -1,5 +0,0 @@
-
diff --git a/test/fixtures/duplicate-cssm.css b/test/fixtures/duplicate-cssm.css
deleted file mode 100644
index 611d25565..000000000
--- a/test/fixtures/duplicate-cssm.css
+++ /dev/null
@@ -1 +0,0 @@
-@value color: red;
diff --git a/test/fixtures/duplicate-cssm.js b/test/fixtures/duplicate-cssm.js
deleted file mode 100644
index 20c5905e3..000000000
--- a/test/fixtures/duplicate-cssm.js
+++ /dev/null
@@ -1,7 +0,0 @@
-import values from './duplicate-cssm.css'
-import Comp from './duplicate-cssm.vue'
-
-export { values }
-export default Comp
-
-window.exports = values
diff --git a/test/fixtures/duplicate-cssm.vue b/test/fixtures/duplicate-cssm.vue
deleted file mode 100644
index 0d37d0bd0..000000000
--- a/test/fixtures/duplicate-cssm.vue
+++ /dev/null
@@ -1,11 +0,0 @@
-
- hi
-
-
-
diff --git a/test/fixtures/empty-style.vue b/test/fixtures/empty-style.vue
deleted file mode 100644
index 12b50f3a7..000000000
--- a/test/fixtures/empty-style.vue
+++ /dev/null
@@ -1,6 +0,0 @@
-
- empty style
-
-
-
diff --git a/test/fixtures/entry.js b/test/fixtures/entry.js
index b5a73e277..a011a5b1f 100644
--- a/test/fixtures/entry.js
+++ b/test/fixtures/entry.js
@@ -1,17 +1,7 @@
-import { createApp } from 'vue'
-
-import Component from '~target'
-import * as exports from '~target'
+const Component = require('~target')
if (typeof window !== 'undefined') {
- window.componentModule = Component
- window.exports = exports
-
- const app = createApp(Component)
- const container = window.document.createElement('div')
- container.id = 'app'
- window.instance = app.mount(container)
- window.document.body.appendChild(container)
+ window.vueModule = Component
}
-export default Component
+module.exports = Component
diff --git a/test/fixtures/es2015.vue b/test/fixtures/es2015.vue
new file mode 100644
index 000000000..5b2cb1ba5
--- /dev/null
+++ b/test/fixtures/es2015.vue
@@ -0,0 +1,3 @@
+
+
+
diff --git a/test/fixtures/extend.vue b/test/fixtures/extend.vue
new file mode 100644
index 000000000..ca11dfe65
--- /dev/null
+++ b/test/fixtures/extend.vue
@@ -0,0 +1,12 @@
+
+ {{ msg }}
+
+
+
diff --git a/test/fixtures/extract-css-chunks.vue b/test/fixtures/extract-css-chunks.vue
deleted file mode 100644
index 80c5e182f..000000000
--- a/test/fixtures/extract-css-chunks.vue
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/test/fixtures/extract-css.vue b/test/fixtures/extract-css.vue
index 7e2e60be0..75034b07c 100644
--- a/test/fixtures/extract-css.vue
+++ b/test/fixtures/extract-css.vue
@@ -3,12 +3,8 @@ h1
color red
-
-
-
diff --git a/test/fixtures/functional-root.vue b/test/fixtures/functional-root.vue
new file mode 100644
index 000000000..e0612e0f1
--- /dev/null
+++ b/test/fixtures/functional-root.vue
@@ -0,0 +1,18 @@
+
+
+
+ hello
+ Second slot
+ {{ scope.msg }}
+
+
+
+
+
diff --git a/test/fixtures/functional-style.vue b/test/fixtures/functional-style.vue
new file mode 100644
index 000000000..70f575f43
--- /dev/null
+++ b/test/fixtures/functional-style.vue
@@ -0,0 +1,12 @@
+
+
+
diff --git a/test/fixtures/functional.vue b/test/fixtures/functional.vue
new file mode 100644
index 000000000..67a44b636
--- /dev/null
+++ b/test/fixtures/functional.vue
@@ -0,0 +1,22 @@
+
+
+
{{ props.msg }}
+
+
+
+
Some text
+
Not exist
+
+
+
+
+
diff --git a/test/fixtures/i18n-entry.js b/test/fixtures/i18n-entry.js
deleted file mode 100644
index 6c1ffb43c..000000000
--- a/test/fixtures/i18n-entry.js
+++ /dev/null
@@ -1,23 +0,0 @@
-import { createApp } from 'vue'
-import { createI18n } from 'vue-i18n'
-
-import Component from './i18n.vue'
-import * as exports from './i18n.vue'
-
-const i18n = createI18n({
- locale: 'de',
- silentFallbackWarn: true,
- silentTranslationWarn: true,
-})
-
-if (typeof window !== 'undefined') {
- window.componentModule = Component
- window.exports = exports
-
- const app = createApp(Component).use(i18n)
-
- const container = window.document.createElement('div')
- window.instance = app.mount(container)
-}
-
-export default Component
diff --git a/test/fixtures/i18n.vue b/test/fixtures/i18n.vue
deleted file mode 100644
index 1d9d6bc75..000000000
--- a/test/fixtures/i18n.vue
+++ /dev/null
@@ -1,7 +0,0 @@
-
- {{ $t('test') }}
-
-
-
-test: Example Text
-
diff --git a/test/fixtures/imported-types-aliased.ts b/test/fixtures/imported-types-aliased.ts
deleted file mode 100644
index 21f0074ca..000000000
--- a/test/fixtures/imported-types-aliased.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export interface Props {
- id?: number
-}
diff --git a/test/fixtures/imported-types.ts b/test/fixtures/imported-types.ts
deleted file mode 100644
index 7c9d47a62..000000000
--- a/test/fixtures/imported-types.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export interface Props {
- msg: string
-}
diff --git a/test/fixtures/imported-types.vue b/test/fixtures/imported-types.vue
deleted file mode 100644
index 35f42ed15..000000000
--- a/test/fixtures/imported-types.vue
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
- {{ Object.keys(props) }}
-
diff --git a/test/fixtures/index.html b/test/fixtures/index.html
deleted file mode 100644
index 7e5123ef1..000000000
--- a/test/fixtures/index.html
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/test/fixtures/markdown.vue b/test/fixtures/markdown.vue
index 113f4118d..ea398f3d6 100644
--- a/test/fixtures/markdown.vue
+++ b/test/fixtures/markdown.vue
@@ -1,11 +1 @@
-## {{msg}}
-
-
+## {{msg}}
diff --git a/test/fixtures/media-query.vue b/test/fixtures/media-query.vue
new file mode 100644
index 000000000..9dbe0ee21
--- /dev/null
+++ b/test/fixtures/media-query.vue
@@ -0,0 +1,7 @@
+
diff --git a/test/fixtures/multiple-rules-1.vue b/test/fixtures/multiple-rules-1.vue
new file mode 100644
index 000000000..858b3eb1e
--- /dev/null
+++ b/test/fixtures/multiple-rules-1.vue
@@ -0,0 +1,9 @@
+
+ Hello World
+
+
+
diff --git a/test/fixtures/multiple-rules-2.vue b/test/fixtures/multiple-rules-2.vue
new file mode 100644
index 000000000..97d226939
--- /dev/null
+++ b/test/fixtures/multiple-rules-2.vue
@@ -0,0 +1,9 @@
+
+ Hello World
+
+
+
diff --git a/test/fixtures/multiple-rules.js b/test/fixtures/multiple-rules.js
new file mode 100644
index 000000000..fa741e723
--- /dev/null
+++ b/test/fixtures/multiple-rules.js
@@ -0,0 +1,4 @@
+import Rule1 from './multiple-rules-1.vue'
+import Rule2 from './multiple-rules-2.vue'
+
+window.rules = [Rule1, Rule2]
diff --git a/test/fixtures/named-exports.vue b/test/fixtures/named-exports.vue
index d9637d3ef..fe873668a 100644
--- a/test/fixtures/named-exports.vue
+++ b/test/fixtures/named-exports.vue
@@ -2,8 +2,8 @@
export default {
name: 'named-exports'
}
+
export function foo () {
return 1
}
-Terms
diff --git a/test/fixtures/no-script.vue b/test/fixtures/no-script.vue
deleted file mode 100644
index 8ad98e3d4..000000000
--- a/test/fixtures/no-script.vue
+++ /dev/null
@@ -1,9 +0,0 @@
-
- hello
-
-
-
diff --git a/test/fixtures/optional-chaining.vue b/test/fixtures/optional-chaining.vue
deleted file mode 100644
index 7e5139ce5..000000000
--- a/test/fixtures/optional-chaining.vue
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
diff --git a/test/fixtures/postcss-lang.vue b/test/fixtures/postcss-lang.vue
new file mode 100644
index 000000000..0f3255f1f
--- /dev/null
+++ b/test/fixtures/postcss-lang.vue
@@ -0,0 +1,6 @@
+
diff --git a/test/fixtures/postcss.vue b/test/fixtures/postcss.vue
index 5507870e1..a02d550de 100644
--- a/test/fixtures/postcss.vue
+++ b/test/fixtures/postcss.vue
@@ -1,8 +1,4 @@
-
-
-
diff --git a/test/fixtures/scoped-css.vue b/test/fixtures/scoped-css.vue
index 2ee0015a1..cd5f74676 100644
--- a/test/fixtures/scoped-css.vue
+++ b/test/fixtures/scoped-css.vue
@@ -25,58 +25,33 @@ h1 {
animation-name: color, opacity;
animation-duration: 5s, 2s;
}
+
@keyframes color {
- from {
- color: red;
- }
- to {
- color: green;
- }
+ from { color: red; }
+ to { color: green; }
}
@-webkit-keyframes color {
- from {
- color: red;
- }
- to {
- color: green;
- }
+ from { color: red; }
+ to { color: green; }
}
@keyframes opacity {
- from {
- opacity: 0;
- }
- to {
- opacity: 1;
- }
+ from { opacity: 0; }
+ to { opacity: 1; }
}
@-webkit-keyframes opacity {
- from {
- opacity: 0;
- }
- to {
- opacity: 1;
- }
+ from { opacity: 0; }
+ to { opacity: 1; }
}
-.foo p ::v-deep(.bar) {
+.foo p >>> .bar {
color: red;
}
-
+
-
-
diff --git a/test/fixtures/script-import.js b/test/fixtures/script-import.js
index ce0b6a81c..03622bda2 100644
--- a/test/fixtures/script-import.js
+++ b/test/fixtures/script-import.js
@@ -1,7 +1,7 @@
export default {
- data() {
+ data () {
return {
- msg: 'Hello from Component A!',
+ msg: 'Hello from Component A!'
}
- },
+ }
}
diff --git a/test/fixtures/script-import.vue b/test/fixtures/script-import.vue
index 08f329768..b45d1ec73 100644
--- a/test/fixtures/script-import.vue
+++ b/test/fixtures/script-import.vue
@@ -1 +1 @@
-
+
\ No newline at end of file
diff --git a/test/fixtures/ssr-style.js b/test/fixtures/ssr-style.js
new file mode 100644
index 000000000..10055bfa2
--- /dev/null
+++ b/test/fixtures/ssr-style.js
@@ -0,0 +1,6 @@
+import Vue from 'vue'
+import App from './ssr-style.vue'
+
+export default () => new Vue({
+ render: h => h(App)
+})
diff --git a/test/fixtures/ssr-style.vue b/test/fixtures/ssr-style.vue
new file mode 100644
index 000000000..55d15f674
--- /dev/null
+++ b/test/fixtures/ssr-style.vue
@@ -0,0 +1,25 @@
+
+
+
Hello
+
+
+
+
+
+
+
+
+
+
diff --git a/test/fixtures/style-import.vue b/test/fixtures/style-import.vue
index 3979d6457..54b83bf89 100644
--- a/test/fixtures/style-import.vue
+++ b/test/fixtures/style-import.vue
@@ -1,6 +1,2 @@
-
-
diff --git a/test/fixtures/style-v-bind.vue b/test/fixtures/style-v-bind.vue
deleted file mode 100644
index 143bdb326..000000000
--- a/test/fixtures/style-v-bind.vue
+++ /dev/null
@@ -1,25 +0,0 @@
-
- hello
-
-
-
-
-
diff --git a/test/fixtures/sub/.postcssrc.js b/test/fixtures/sub/.postcssrc.js
new file mode 100644
index 000000000..961986e2b
--- /dev/null
+++ b/test/fixtures/sub/.postcssrc.js
@@ -0,0 +1,5 @@
+module.exports = {
+ plugins: {
+ autoprefixer: {}
+ }
+}
diff --git a/test/fixtures/sub/postcss-cascade.vue b/test/fixtures/sub/postcss-cascade.vue
new file mode 100644
index 000000000..82fdf388f
--- /dev/null
+++ b/test/fixtures/sub/postcss-cascade.vue
@@ -0,0 +1,3 @@
+
diff --git a/test/fixtures/supports-query.vue b/test/fixtures/supports-query.vue
new file mode 100644
index 000000000..88db49709
--- /dev/null
+++ b/test/fixtures/supports-query.vue
@@ -0,0 +1,7 @@
+
diff --git a/test/fixtures/template-comment.vue b/test/fixtures/template-comment.vue
new file mode 100644
index 000000000..a72b02fa4
--- /dev/null
+++ b/test/fixtures/template-comment.vue
@@ -0,0 +1,16 @@
+
+
+
{{msg}}
+
+
+
+
diff --git a/test/fixtures/template-import-pre.vue b/test/fixtures/template-import-pre.vue
deleted file mode 100644
index 461624104..000000000
--- a/test/fixtures/template-import-pre.vue
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/test/fixtures/template-import.html b/test/fixtures/template-import.html
deleted file mode 100644
index c9dc2eef3..000000000
--- a/test/fixtures/template-import.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
hello
-
diff --git a/test/fixtures/template-import.vue b/test/fixtures/template-import.vue
index 00de859d2..461624104 100644
--- a/test/fixtures/template-import.vue
+++ b/test/fixtures/template-import.vue
@@ -1 +1 @@
-
+
diff --git a/test/fixtures/transform.vue b/test/fixtures/transform.vue
new file mode 100644
index 000000000..f43b47c69
--- /dev/null
+++ b/test/fixtures/transform.vue
@@ -0,0 +1,24 @@
+
+
+
+
+
diff --git a/test/fixtures/ts.vue b/test/fixtures/ts.vue
deleted file mode 100644
index 95031a7f2..000000000
--- a/test/fixtures/ts.vue
+++ /dev/null
@@ -1,11 +0,0 @@
-
- {{ msg }}
-
-
-
-
-
diff --git a/test/fixtures/tsconfig.json b/test/fixtures/tsconfig.json
deleted file mode 100644
index 2aee38a15..000000000
--- a/test/fixtures/tsconfig.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "compilerOptions": {
- "paths": {
- "foo": ["./imported-types-aliased.ts"]
- }
- },
- "include": ["."]
-}
diff --git a/test/fixtures/unit-test.js b/test/fixtures/unit-test.js
index 70d411983..a44105ba9 100644
--- a/test/fixtures/unit-test.js
+++ b/test/fixtures/unit-test.js
@@ -1,5 +1,5 @@
-describe('example', () => {
- it('basic', (done) => {
- done()
+ describe('example', function () {
+ it('basic', function (done) {
+ done()
+ })
})
-})
diff --git a/test/mock-loaders/blog.js b/test/mock-loaders/blog.js
new file mode 100644
index 000000000..d441233af
--- /dev/null
+++ b/test/mock-loaders/blog.js
@@ -0,0 +1,8 @@
+function normalize (code) {
+ return code.split(/\r?\n/).map(function (line) { return line }).join('')
+}
+
+module.exports = function (source) {
+ var code = "module.exports = function (Component) { Component.options.__blog = '" + source + "' }"
+ return normalize(code)
+}
diff --git a/test/mock-loaders/css.js b/test/mock-loaders/css.js
new file mode 100644
index 000000000..fe5d6d1e2
--- /dev/null
+++ b/test/mock-loaders/css.js
@@ -0,0 +1,3 @@
+module.exports = function (content) {
+ return content.replace(/#f00/, '#00f')
+}
diff --git a/test/mock-loaders/docs.js b/test/mock-loaders/docs.js
index c79cd45c0..f0e749e4a 100644
--- a/test/mock-loaders/docs.js
+++ b/test/mock-loaders/docs.js
@@ -1,9 +1,7 @@
module.exports = function (source, map) {
- this.callback(
- null,
- `export default Component => {
- Component.__docs = ${JSON.stringify(source)}
- }`,
- map
- )
+ this.callback(null,
+ 'module.exports = function(Component) {Component.options.__docs = ' +
+ JSON.stringify(source) +
+ '}',
+ map)
}
diff --git a/test/mock-loaders/i18n.js b/test/mock-loaders/i18n.js
new file mode 100644
index 000000000..718312e14
--- /dev/null
+++ b/test/mock-loaders/i18n.js
@@ -0,0 +1,6 @@
+module.exports = function (source) {
+ var value = typeof source === 'string' ? JSON.parse(source) : source
+ var jsonString = JSON.stringify(value).replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029')
+ var code = 'module.exports = function (Component) { Component.options.__i18n = ' + JSON.stringify(jsonString) + ' }'
+ this.callback(null, code)
+}
diff --git a/test/mock-loaders/identity.js b/test/mock-loaders/identity.js
new file mode 100644
index 000000000..1590b7f40
--- /dev/null
+++ b/test/mock-loaders/identity.js
@@ -0,0 +1,3 @@
+module.exports = function (source, map) {
+ this.callback(null, source, map)
+}
diff --git a/test/mock-loaders/query.js b/test/mock-loaders/query.js
deleted file mode 100644
index 0a2ff8727..000000000
--- a/test/mock-loaders/query.js
+++ /dev/null
@@ -1,22 +0,0 @@
-module.exports = function (content) {
- const query = this.resourceQuery.slice(1)
-
- if (/change/.test(query)) {
- return `
-
- Changed!
-
-
- `
- }
-
- return content
-}
diff --git a/test/mock-loaders/yaml.js b/test/mock-loaders/yaml.js
new file mode 100644
index 000000000..a27de0b5a
--- /dev/null
+++ b/test/mock-loaders/yaml.js
@@ -0,0 +1,7 @@
+var yaml = require('js-yaml')
+
+module.exports = function (source) {
+ this.cacheable && this.cacheable()
+ var res = yaml.safeLoad(source)
+ return JSON.stringify(res)
+}
diff --git a/test/script.js b/test/script.js
new file mode 100644
index 000000000..96b9cb3e9
--- /dev/null
+++ b/test/script.js
@@ -0,0 +1,34 @@
+process.env.VUE_LOADER_TEST = true
+
+const { expect } = require('chai')
+const {
+ mockBundleAndRun,
+ mockRender
+} = require('./shared')
+
+describe('script block features', () => {
+ it('allows to export extended constructor', done => {
+ mockBundleAndRun({
+ entry: 'extend.vue'
+ }, (window, Module) => {
+ // extend.vue should export Vue constructor
+ const vnode = mockRender(Module.options, {
+ msg: 'success'
+ })
+ expect(vnode.tag).to.equal('div')
+ expect(vnode.children[0].text).to.equal('success')
+ expect(new Module().msg === 'success')
+ done()
+ })
+ })
+
+ it('named exports', done => {
+ mockBundleAndRun({
+ entry: 'named-exports.vue'
+ }, (window, _, rawModule) => {
+ expect(rawModule.default.name).to.equal('named-exports')
+ expect(rawModule.foo()).to.equal(1)
+ done()
+ })
+ })
+})
diff --git a/test/script.spec.ts b/test/script.spec.ts
deleted file mode 100644
index e20f75d13..000000000
--- a/test/script.spec.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-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