diff --git a/README.md b/README.md index 66fa388..59234ed 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,27 @@ These are the preprocessors supported by vueify out of the box: - pug - coffee-script (use `coffee` in [config section](#configuring-options)) +## Building for modern browsers + +If you're developing for modern browsers and you don't need to transpile your code you can use `noncompiled` value in lang attribute. +Just make sure to use `commonjs` module syntax: + +``` vue + + + +``` + ## PostCSS Vueify uses PostCSS for scoped CSS rewrite. You can also provide your own PostCSS plugins! See [config section](#configuring-options) below for an example. diff --git a/lib/compilers/babel.js b/lib/compilers/babel.js index d999bfa..d237ed6 100644 --- a/lib/compilers/babel.js +++ b/lib/compilers/babel.js @@ -23,20 +23,20 @@ function getBabelRc () { return rc } -if (babelOptions === defaultBabelOptions) { - try { - ensureRequire('babel', ['babel-preset-es2015', 'babel-runtime', 'babel-plugin-transform-runtime']) - } catch (e) { - console.error(e.message) - console.error( - '\n^^^ You are seeing this because you are using Vueify\'s default babel ' + - 'configuration. You can override this with .babelrc or the babel option ' + - 'in vue.config.js.' - ) +module.exports = function (raw, cb, compiler, filePath) { + if (babelOptions === defaultBabelOptions) { + try { + ensureRequire('babel', ['babel-preset-es2015', 'babel-runtime', 'babel-plugin-transform-runtime']) + } catch (e) { + console.error(e.message) + console.error( + '\n^^^ You are seeing this because you are using Vueify\'s default babel ' + + 'configuration. You can override this with .babelrc or the babel option ' + + 'in vue.config.js.' + ) + } } -} -module.exports = function (raw, cb, compiler, filePath) { try { var babel = require('babel-core') var options = assign({ diff --git a/lib/compilers/noncompiled.js b/lib/compilers/noncompiled.js new file mode 100644 index 0000000..a291a46 --- /dev/null +++ b/lib/compilers/noncompiled.js @@ -0,0 +1,6 @@ +var ensureRequire = require('../ensure-require.js') + +module.exports = function (raw, cb) { + ensureRequire('skip-compilers', []) + cb(null, raw) +} diff --git a/test/fixtures/noncompiled.vue b/test/fixtures/noncompiled.vue new file mode 100644 index 0000000..00fd1f9 --- /dev/null +++ b/test/fixtures/noncompiled.vue @@ -0,0 +1,13 @@ + + + diff --git a/test/fixtures/script-import.js b/test/fixtures/script-import.js index 8ab2015..03622bd 100644 --- a/test/fixtures/script-import.js +++ b/test/fixtures/script-import.js @@ -4,4 +4,4 @@ export default { msg: 'Hello from Component A!' } } -}; \ No newline at end of file +} diff --git a/test/test.js b/test/test.js index 69d3e4b..5fdd86d 100644 --- a/test/test.js +++ b/test/test.js @@ -134,6 +134,12 @@ describe('vueify', () => { expect(style).to.contain('@media print {\n .foo[' + id + '] {\n color: #000;\n }\n}') }) + test('noncompiled', window => { + const module = window.vueModule + assertRenderFn(module, '

{{msg}}

') + expect(module.data().msg).to.contain('Hello from Non Compiled Component!') + }) + testCssExtract('style-export', css => { expect(css).to.equal('h2 {color: red;}') })