nativescript - webpack错误

时间:2017-09-30 14:51:42

标签: webpack nativescript

尝试将webpack整合到我的Android应用中。

关于NS Webpack的说明。

  1. 当我尝试构建应用程序时 - 我收到错误app.css未找到。我没有,因为我使用的是scss。为什么webpack正在寻找app.css。
  2. 我输入了一个虚拟文件并超过了该错误 - 并且构建正常。

    1. 当我尝试运行它时,我得到:
    2. 
      
      Preparing project...
      Project successfully prepared (Android)
      Executing after-prepare hook from C:\Users\MyPC\nativescript\test4b\hooks\after-prepare\nativescript-dev-sass.js
      All SASS source files removed from app package
      Skipping package build. No changes detected on the native side. This will be fast!
      Installing...
      Successfully installed on device with identifier 'emulator-5554'.
      Starting...
      Successfully started on device with identifier 'emulator-5554'.
      JS: Subscription constr ***
      JS: APP LAUNCHED Intent { flg=0x10000000 cmp=dev.crewapps.test/com.tns.NativeScriptActivity }
      System.err: java.lang.RuntimeException: Unable to start activity ComponentInfo{dev.crewapps.test/com.tns.NativeScriptAct
      ivity}: com.tns.NativeScriptException:
      System.err: Calling js method onCreate failed
      System.err: Error: Building UI from XML. @file:///app/cal-page.xml:31:9
      System.err:  > Module '/data/data/dev.crewapps.test/files/app/nativescript-telerik-ui/sidedrawer' not found for element
      'nativescript-telerik-ui/sidedrawer:RadSideDrawer'.
      System.err:    > com.tns.NativeScriptException: Failed to find module: "/data/data/dev.crewapps.test/files/app/nativescr
      ipt-telerik-ui/sidedrawer", relative to: app//
      System.err:       com.tns.Module.resolvePathHelper(Module.java:146)
      System.err:     com.tns.Module.resolvePath(Module.java:55)
      System.err:     com.tns.Runtime.callJSMethodNative(Native Method)
      System.err:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1084)
      System.err:     com.tns.Runtime.callJSMethodImpl(Runtime.java:966)
      System.err:     com.tns.Runtime.callJSMethod(Runtime.java:953)
      System.err:     com.tns.Runtime.callJSMethod(Runtime.java:937)
      System.err:     com.tns.Runtime.callJSMethod(Runtime.java:929)
      System.err:     com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:13)
      System.err:     android.app.Activity.performCreate(Activity.java:6237)
      System.err:     android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
      System.err:     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
      System.err:     android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
      System.err:     android.app.ActivityThread.-wrap11(ActivityThread.java)
      System.err:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
      System.err:     android.os.Handler.dispatchMessage(Handler.java:102)
      System.err:     android.os.Looper.loop(Looper.java:148)
      System.err:     android.app.ActivityThread.main(ActivityThread.java:5417)
      System.err:     java.lang.reflect.Method.invoke(Native Method)
      System.err:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
      System.err:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
      System.err: File: "file:///data/data/dev.crewapps.test/files/app/vendor.js, line: 9461, column: 20
      System.err: StackTrace:
      System.err:     Frame: function:'ScopeError', file:'file:///data/data/dev.crewapps.test/files/app/vendor.js', line: 8202
      , column: 24
      System.err:     Frame: function:'SourceError', file:'file:///data/data/dev.crewapps.test/files/app/vendor.js', line: 821
      3, column: 23
      System.err:     Frame: function:'', file:'file:///data/data/dev.crewapps.test/files/app/vendor.js', line: 9480, column:
      17
      System.err:     Frame: function:'', file:'file:///data/data/dev.crewapps.test/files/app/vendor.js', line: 9461, column:
      33
      System.err:     Frame: function:'', file:'file:///data/data/dev.crewapps.test/files/app/vendor.js', line: 25470, column:
       13
      System.err:     Frame: function:'module.exports.EasySAXParser.parse', file:'file:///data/data/dev.crewapps.test/files/ap
      p/vendor.js', line: 26338, column: 23
      System.err:     Frame: function:'module.exports.XmlParser.parse', file:'file:///data/data/dev.crewapps.test/files/app/ve
      ndor.js', line: 25517, column: 22
      System.err:     Frame: function:'module.exports.XmlStringParser.parse', file:'file:///data/data/dev.crewapps.test/files/
      app/vendor.js', line: 9467, column: 27
      System.err:     Frame: function:'parseInternal', file:'file:///data/data/dev.crewapps.test/files/app/vendor.js', line: 9
      312, column: 11
      System.err:     Frame: function:'loadPage', file:'file:///data/data/dev.crewapps.test/files/app/vendor.js', line: 9396,
      column: 27
      System.err:     Frame: function:'', file:'file:///data/data/dev.crewapps.test/files/app/vendor.js', line: 11473, column:
       26
      System.err:     Frame: function:'', file:'file:///data/data/dev.crewapps.test/files/app/vendor.js', line: 11492, column:
       20
      System.err:     Frame: function:'module.exports.FrameBase.navigate', file:'file:///data/data/dev.crewapps.test/files/app
      /vendor.js', line: 11548, column: 28
      System.err:     Frame: function:'module.exports.ActivityCallbacksImplementation.onCreate', file:'file:///data/data/dev.c
      rewapps.test/files/app/vendor.js', line: 2829, column: 19
      System.err:     Frame: function:'module.exports.NativeScriptActivity.onCreate', file:'file:///data/data/dev.crewapps.tes
      t/files/app/vendor.js', line: 31337, column: 25
      System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
      System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
      System.err:     at android.app.ActivityThread.-wrap11(ActivityThread.java)
      System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
      System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
      System.err:     at android.os.Looper.loop(Looper.java:148)
      System.err:     at android.app.ActivityThread.main(ActivityThread.java:5417)
      System.err:     at java.lang.reflect.Method.invoke(Native Method)
      System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
      System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
      System.err: Caused by: com.tns.NativeScriptException:
      System.err: Calling js method onCreate failed
      System.err: Error: Building UI from XML. @file:///app/cal-page.xml:31:9
      
      
      

      这个应用程序在没有webpack的情况下工作正常 - 所以我知道xml和插件设置是正确的。

      存在侧边插件。

      任何帮助?

      webpack.config.js

      
      
      const { resolve, join  } = require("path");
      
      const webpack = require("webpack");
      const nsWebpack = require("nativescript-dev-webpack");
      const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
      const CopyWebpackPlugin = require("copy-webpack-plugin");
      const ExtractTextPlugin = require("extract-text-webpack-plugin");
      const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
      const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
      
      
      const mainSheet = `app.css`;
      
      module.exports = env => {
          const platform = getPlatform(env);
      
          // Default destination inside platforms/<platform>/...
          const path = resolve(nsWebpack.getAppPath(platform));
      
          const entry = {
              // Discover entry module from package.json
              bundle: `./${nsWebpack.getEntryModule()}`,
      
              // Vendor entry with third-party libraries
              vendor: `./vendor`,
      
              // Entry for stylesheet with global application styles
              [mainSheet]: `./${mainSheet}`,
          };
      
          const rules = getRules();
          const plugins = getPlugins(platform, env);
          const extensions = getExtensions(platform);
      
          const config = {
              context: resolve("./app"),
              target: nativescriptTarget,
              entry,
              output: {
                  pathinfo: true,
                  path,
                  libraryTarget: "commonjs2",
                  filename: "[name].js",
              },
              resolve: {
                  extensions,
      
                  // Resolve {N} system modules from tns-core-modules
                  modules: [
                      "node_modules/tns-core-modules",
                      "node_modules",
                  ],
      
                  alias: {
                      '~': resolve("./app")
                  },
              },
              node: {
                  // Disable node shims that conflict with NativeScript
                  "http": false,
                  "timers": false,
                  "setImmediate": false,
                  "fs": "empty",
              },
              module: { rules },
              plugins,
          };
      
          if (env.snapshot) {
              plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
                  chunk: "vendor",
                  projectRoot: __dirname,
                  webpackConfig: config,
                  targetArchs: ["arm", "arm64", "ia32"],
                  tnsJavaClassesOptions: { packages: ["tns-core-modules" ] },
                  useLibs: false
              }));
          }
      
          return config;
      };
      
      
      function getPlatform(env) {
          return env.android ? "android" :
              env.ios ? "ios" :
              () => { throw new Error("You need to provide a target platform!") };
      }
      
      function getRules() {
          return [
              {
                  test: /\.html$|\.xml$/,
                  use: [
                      "raw-loader",
                  ]
              },
              // Root stylesheet gets extracted with bundled dependencies
              {
                  test: new RegExp(mainSheet),
                  use: ExtractTextPlugin.extract([
                      {
                          loader: "resolve-url-loader",
                          options: { silent: true },
                      },
                      {
                          loader: "nativescript-css-loader",
                          options: { minimize: false }
                      },
                      "nativescript-dev-webpack/platform-css-loader",
                  ]),
              },
              // Other CSS files get bundled using the raw loader
              {
                  test: /\.css$/,
                  exclude: new RegExp(mainSheet),
                  use: [
                      "raw-loader",
                  ]
              },
              // SASS support
              {
                  test: /\.scss$/,
                  use: [
                      "raw-loader",
                      "resolve-url-loader",
                      "sass-loader",
                  ]
              },
      
      
              // Compile TypeScript files, replace templateUrl and styleUrls.
              {
                  test: /\.ts$/,
                  loaders: [
                      "awesome-typescript-loader",
                  ]
              }
      
          ];
      }
      
      function getPlugins(platform, env) {
          let plugins = [
              new ExtractTextPlugin(mainSheet),
      
              // Vendor libs go to the vendor.js chunk
              new webpack.optimize.CommonsChunkPlugin({
                  name: ["vendor"],
              }),
      
              // Define useful constants like TNS_WEBPACK
              new webpack.DefinePlugin({
                  "global.TNS_WEBPACK": "true",
              }),
      
              // Copy assets to out dir. Add your own globs as needed.
              new CopyWebpackPlugin([
                  { from: mainSheet },
                  { from: "css/**" },
                  { from: "fonts/**" },
                  { from: "**/*.jpg" },
                  { from: "**/*.png" },
                  { from: "**/*.xml" },
              ], { ignore: ["App_Resources/**"] }),
      
              // Generate a bundle starter script and activate it in package.json
              new nsWebpack.GenerateBundleStarterPlugin([
                  "./vendor",
                  "./bundle",
              ]),
              
              // Support for web workers since v3.2
              new NativeScriptWorkerPlugin(),
      
              // Generate report files for bundles content
              new BundleAnalyzerPlugin({
                  analyzerMode: "static",
                  openAnalyzer: false,
                  generateStatsFile: true,
                  reportFilename: join(__dirname, "report", `report.html`),
                  statsFilename: join(__dirname, "report", `stats.json`),
              }),
          ];
      
          if (env.uglify) {
              plugins.push(new webpack.LoaderOptionsPlugin({ minimize: true }));
      
              // Work around an Android issue by setting compress = false
              const compress = platform !== "android";
              plugins.push(new webpack.optimize.UglifyJsPlugin({
                  mangle: { except: nsWebpack.uglifyMangleExcludes },
                  compress,
              }));
          }
      
          return plugins;
      }
      
      // Resolve platform-specific modules like module.android.js
      function getExtensions(platform) {
          return Object.freeze([
              `.${platform}.ts`,
              `.${platform}.js`,
              ".ts",
              ".js",
              ".css",
              `.${platform}.css`,
          ]);
      }
      &#13;
      &#13;
      &#13;

      我看到app.css的主要工作表定义 - 我可以对此进行评论吗?

      ns 3.2 nativescript-dev-webpack 0.8.0

0 个答案:

没有答案