【问题标题】:trying to use webpack with existing angular1 applicaiton尝试将 webpack 与现有的 angular 1 应用程序一起使用
【发布时间】:2018-08-09 09:44:00
【问题描述】:

我有一个现有的 angular1 应用程序,我正在尝试实现 web pack

源码修改

而webpack如下图

所有的依赖都包含在 package.json 中

关注这篇文章

http://matthamil.me/blog/Angular-1-and-Webpack/

import webpack from 'webpack';

module.exports = {
    // This creates a source map to make your
    // console errors a lot more developer friendly
    devtool: 'inline-source-map',
    // Webpack will start doing its thing here
    entry: {
        app: './app/app.js',
        vendor: ['angular']
    },
    // Where Webpack spits the output
    output: {
        path: __dirname + '/dist',
        filename:  "[name].js"
    },
    module: {
        // These are Webpack plugins (commonly referred
        // to as "loaders" in the Webpack community).
        // Babel will compile our ES6 to ES5
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader'
            }
        ]
    }
};

当我运行 webpack 时显示以下错误

/home/dl/projects/zd /webpackangular1app/webpack.config.js:1
(function (exports, require, module, __filename, __dirname) { import webpack from 'webpack';
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at NativeCompileCache._moduleCompile (/usr/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:226:18)

请说明如何在 webpack.config.js 中使用 import webpack 尝试了许多类似 require 的方法,但没有成功,请指出参考或建议一种方法

【问题讨论】:

    标签: webpack build config angular1.6


    【解决方案1】:

    Node 还不支持 ES 导入语法,您正在尝试在 webpack 配置文件中使用它。

    Webpack 不会通过您定义的加载器等传递您的配置文件,因此您的配置不会通过 Babel。

    改变这个:

    import webpack from 'webpack';
    

    到这里:

    var webpack = require('webpack')
    

    【讨论】:

      最近更新 更多