webpack - 在 webpack 构建期间使用 aurelia-webpack-plugin 时出现意外的 token 错误

标签 webpack aurelia webpack-2

库版本:
aurelia-webpack-plugin@2.0.0-rc.1(分支:v2.0)

操作系统:
视窗 8
节点版本:
6.7.0
NPM 版本:
3.10.8
网络包版本
网络包 2.2.1
浏览器:
全部
语:
typescript 2.1
当前行为:

如果我们在 webpack 配置文件中使用 aurelia-webpack-plugin,我们会在 webpack 构建过程中遇到错误。错误显示“SyntaxError: Unexpected token =”

enter image description here

包.json

     "dependencies": {
    "aurelia-bootstrapper-webpack": "^1.0.0",
    "aurelia-event-aggregator": "^1.0.0",
    "aurelia-framework": "^1.0.1",
    "aurelia-history-browser": "^1.0.0",
    "aurelia-loader-webpack": "^1.0.2",
    "aurelia-logging-console": "^1.0.0",
    "aurelia-templating-binding": "^1.0.0",
    "aurelia-templating-resources": "^1.0.0",
    "aurelia-templating-router": "^1.0.0"
  },
  "devDependencies": {
    "aurelia-webpack-plugin": "git+https://github.com/aurelia/webpack-plugin.git#v2.0",
    "html-loader": "^0.4.3",
    "source-map-loader": "^0.1.5",
    "webpack": "^2.2.1"
  }

配置文件
    {
  "compilerOptions": {
    "target": "es5",
    "module": "amd",   
    "experimentalDecorators": true,
    "strictNullChecks": true,
    "moduleResolution": "node",
    "sourceMap": true,    
    "lib": [
      "es2017",
      "dom"
    ]
  },
  "awesomeTypescriptLoaderOptions": {
    "forkChecker": true
  },
  "exclude": [
    "node_modules",
    "build"  
  ]
}

webpack.config.js
const AureliaWebpackPlugin = require('aurelia-webpack-plugin');
var path = require('path');
// We need this to use the CommonsChunkPlugin.
var webpack = require('webpack');

const baseUrl = '/';
const rootDir = path.resolve();
const srcDir = path.resolve('src');
const outDir = path.resolve('build');


module.exports = {
    entry: {
        // Our app's entry point, this is set automatically by aurelia-webpack-plugin
        // using the files in the "src" folder that we're still going to create.
        // The app knows which of the files is our entry point because of the "aurelia-bootstrapper-webpack" 
        // who reads the entry point from the aurelia-app="main" in our index.html.
        'app': [],       
        //These are all the aurelia libraries, they will be bundled separately from our app's main code.
        //I tried to bundle everything together, with no success.
        'aurelia': [
            'aurelia-bootstrapper-webpack',
            'aurelia-polyfills',
            'aurelia-pal',
            'aurelia-pal-browser',
            'aurelia-binding',
            'aurelia-dependency-injection',
            'aurelia-event-aggregator',
            'aurelia-framework',
            'aurelia-history',
            'aurelia-history-browser',
            'aurelia-loader',
            'aurelia-loader-webpack',
            'aurelia-logging',
            'aurelia-logging-console',
            'aurelia-metadata',
            'aurelia-path',
            'aurelia-route-recognizer',
            'aurelia-router',
            'aurelia-task-queue',
            'aurelia-templating',
            'aurelia-templating-binding',
            'aurelia-templating-router',
            'aurelia-templating-resources'
        ]
    },
   // entry: 'main',
    output: {
        //This is the folder where our packed app will be after we run webpack.
        path: './build',
        filename: 'scripts/[name].bundle.js',
        sourceMapFilename: 'scripts/[name].bundle.js.map'
    },   
   // devtool: 'source-map',
    module: {

        loaders: [
            { test: /\.html$/, use: 'html-loader'},
            { test: /\.json$/, use: 'json-loader'} 
        ]
    },
    plugins: [

        new AureliaWebpackPlugin({
            root: rootDir,
            src: srcDir,           
            baseUrl: baseUrl
        }),
        new webpack.optimize.CommonsChunkPlugin({ name: ['aurelia'] })        
    ],
    // This is not necessary, it just changes the default port the
    // webpack-dev-server uses from 3000 to whatever you set here.
    devServer: {
        port: 53092
    },    
};

最佳答案

Aurelia 团队刚刚为 webpack4 发布了一个 webpack 插件版本
https://github.com/aurelia/webpack-plugin/releases/tag/3.0.0-rc.1

以前版本的 webpack (2 - 3.5) 支持
https://github.com/aurelia/webpack-plugin/releases/tag/2.0.0-rc.5

repo中有一个插件的详细wiki
https://github.com/aurelia/webpack-plugin/wiki

如果您是从头开始并且更喜欢自己动手,这里是具有良好启动配置的 webpack 仓库:
https://github.com/jods4/aurelia-webpack-build

关于webpack - 在 webpack 构建期间使用 aurelia-webpack-plugin 时出现意外的 token 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42366167/

相关文章:

javascript - Electron、React 和 Webpack,如何让 HMR 发挥作用?

javascript - 为什么 Webpack 5 没有 CSS 文件输出?

node.js - 如何使用 aurelia 让 webpack 与 Electron 一起工作?

dependency-injection - Aurelia Typescript DI - 实例化 HTTP 获取

webpack - 客户端请求以前的 webpack 构建发出的文件

javascript - 一旦我设置了nodeIntegration :false -> “Uncaught ReferenceError: require is not defined at Object.url (external ” url“:1) ” #electron-#react-#typescript

javascript - 通过属性将对象传递给自定义组件

node.js - 如何丑化文件并保存到另一个位置(vue.js)

angular - 无法找到模块 './sections/lazy/lazy.module.ngfactory' Angular 2 Webpack + AOT 设置中出现错误

webpack - 如何在DevTools中查看webpack生成的文件