本来一切正常,只是想增加一个 es2017 的语法,加了 babel 就报错。问题复现: https://coding.net/u/hilojack/p/my-rollup-issue/git
➜ vue$ git:(master) ✗rollup -c -w
[!] (babel plugin) SyntaxError: /Users/hilojack/www/egg/vue/src/App.vue: Unexpected token (1:0)
src/App.vue (1:0)
SyntaxError: /Users/hilojack/www/egg/vue/src/App.vue: Unexpected token (1:0)
> 1 | <template>
| ^
2 | <div class="container">
3 | <div class="col-md-6 col-md-offset-3">
4 | <h1>Vue TODO App by ahuigo</h1>
相关配置如下:
➜ vue$ git:(master) ✗cat src/.babelrc
{
"presets": [
[
"latest",
{ "es2015": { "modules": false } }
]
],
"plugins": ["external-helpers", "transform-decorators-legacy", "transform-object-rest-spread", ],
}
➜ vue$ git:(master) ✗cat rollup.config.js
import json from "rollup-plugin-json";
import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import babel from "rollup-plugin-babel";
import VuePlugin from "rollup-plugin-vue";
import replace from 'rollup-plugin-replace';
import uglify from 'rollup-plugin-uglify';
//import postcss from 'rollup-plugin-postcss';
export default{
//input: "src/main.js",
input: ["src/index.js"],
output: {
format: "esm",
name: "myBundle",
dir: "dist",
//file: "dist/bundle.js",
paths: {
d3: "https://d3js.org/d3.v4.min",
vue: "https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.esm.browser.js",
}
},
experimentalCodeSplitting: true,
external: ["lodash", "d3","vue"],
watch: {
//exclude: ['node_modules/**', 'dist/**',], //default ignore
include: ['src/**','src/App.vue'],
},
plugins:[
babel({ exclude: 'node_modules/**' }),
json(),
//resolve({ jsnext: true, main: true, browser: true, }),
resolve({ browser: true, }),
commonjs(),
VuePlugin(),
replace({
exclude: 'node_modules/**',
ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
}),
(process.env.NODE_ENV === 'production' && uglify()),
],
};