V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
a132811
V2EX  ›  Node.js

babel+vue+rollup 集成问题: Unexpected token `<template>`

  •  
  •   a132811 · 2018-09-03 14:51:22 +08:00 · 3706 次点击
    这是一个创建于 2307 天前的主题,其中的信息可能已经有所发展或是发生改变。

    本来一切正常,只是想增加一个 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()),
        ],
    };
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   968 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 19:54 · PVG 03:54 · LAX 11:54 · JFK 14:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.