質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

Q&A

0回答

1271閲覧

Webpackでgsapのプラグインをcdn化したい。

退会済みユーザー

退会済みユーザー

総合スコア0

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

0グッド

0クリップ

投稿2020/05/13 07:57

編集2020/05/14 10:47

webpackのexternalsを使って、typescriptファイル内でインポートしているgsapをcdn化したいのですが、chromeのコンソールに次のようなエラーが出てしまいます。
どのように対処したらよいのでしょうか。

webpackは4.42.1、gsapは3.2.6を使用しています。

CSSPlugin.js:12 Uncaught SyntaxError: Cannot use import statement outside a module PixiPlugin.js:367 Uncaught SyntaxError: Unexpected token 'export'

typescript

1import gsap from "gsap"; 2import PixiPlugin from "gsap/PixiPlugin"; 3import CSSPlugin from "gsap/CSSPlugin"; 4 5const plugins = [PixiPlugin, CSSPlugin]; 6gsap.registerPlugin(plugins); 7export default gsap; 8

typescript

1{ 2 "compilerOptions": { 3 "target": "es5", 4 "module": "es6", 5 "lib": ["dom", "esnext"], 6 "baseUrl": "./src/ts", 7 "outDir": "./dist/js", 8 "sourceMap": false, 9 "allowJs": true, 10 "alwaysStrict": true, 11 "esModuleInterop": true, 12 "forceConsistentCasingInFileNames": true, 13 "isolatedModules": true, 14 "moduleResolution": "node", 15 "noEmit": false, 16 "noFallthroughCasesInSwitch": true, 17 "noUnusedLocals": false, 18 "noUnusedParameters": false, 19 "removeComments": true, 20 "skipLibCheck": true, 21 "strict": true, 22 "noImplicitAny": false, 23 "strictNullChecks": false 24 }, 25 "compileOnSave": true, 26 "include": [ 27 "src/ts/**/*.ts" 28 ], 29 "exclude": [ 30 "node_modules", 31 ], 32} 33

js

1const path = require("path"); 2const WebpackCdnPlugin = require('webpack-cdn-plugin'); 3 4module.exports = { 5 6 entry: { 7 app: "./src/index.ts" 8 }, 9 10 // 出力先 11 output: { 12 filename: "js/[name].js", 13 path: path.join(__dirname, "dist"), 14 libraryTarget: "umd" 15 }, 16 17 module: { 18 rules: [{ 19 test: /.js$/, 20 use: "babel-loader", 21 exclude: /node_modules/ 22 }, { 23 test: /.ts$/, 24 use: "ts-loader", 25 exclude: /node_modules/ 26 } 27 ] 28 }, 29 30 optimization: { 31 usedExports: true, 32 splitChunks: { 33 cacheGroups: { 34 vendor: { 35 test: /node_modules/, 36 name: "vendor", 37 chunks: "initial", 38 } 39 } 40 } 41 }, 42 43 resolve: { 44 extensions: [".ts", ".js"], 45 }, 46 plugins: [ 47 new WebpackCdnPlugin({ 48 modules: [{ 49 name: 'pixi.js', 50 var: 'PIXI', 51 path: 'dist/pixi.min.js' 52 }, 53 { 54 name: 'gsap', 55 path: 'dist/gsap.min.js' 56 }, 57 { 58 name: 'gsap', 59 path: 'CSSPlugin.js' 60 }, 61 { 62 name: 'gsap', 63 path: 'PixiPlugin.js' 64 } 65 ], 66 publicPath: '/node_modules' 67 }) 68 ], 69 externals: [{ 70 "pixi.js": "PIXI", 71 "gsap": "gsap", 72 "gsap/CSSPlugin": "CSSPlugin", 73 "gsap/PixiPlugin": "PixiPlugin" 74 }, 75 ] 76}; 77

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問