|
| 1 | +import { resolve } from 'path'; |
| 2 | +import WrapperPlugin from 'wrapper-webpack-plugin'; |
| 3 | + |
| 4 | +const output = { |
| 5 | + path: resolve('../shim'), |
| 6 | + filename: '[name].js', |
| 7 | + library: { |
| 8 | + type: 'module' |
| 9 | + } |
| 10 | +}; |
| 11 | +const alias = { |
| 12 | + assert: resolve('./shim-assert.cjs'), |
| 13 | + fs: resolve('../shim/fs.js'), |
| 14 | + path: resolve('../shim/path.js'), |
| 15 | + module: resolve('../shim/module.js'), |
| 16 | + url: resolve('../shim/url.js'), |
| 17 | + util: resolve('../shim/util.js'), |
| 18 | + typescript: resolve('../shim/typescript.js') |
| 19 | +}; |
| 20 | +/** @type {import('webpack').Configuration} */ |
| 21 | +const base = { |
| 22 | + output, |
| 23 | + resolve: { |
| 24 | + alias |
| 25 | + }, |
| 26 | + target: ['web'], |
| 27 | + optimization: { |
| 28 | + minimize: false |
| 29 | + }, |
| 30 | + mode: 'production', |
| 31 | + experiments: { |
| 32 | + outputModule: true |
| 33 | + }, |
| 34 | + externalsType: 'var' |
| 35 | +}; |
| 36 | +/** @type {import('webpack').Configuration[]} */ |
| 37 | +export default [ |
| 38 | + { |
| 39 | + ...base, |
| 40 | + entry: { |
| 41 | + 'eslint-scope': resolve('./eslint-scope.js') |
| 42 | + } |
| 43 | + }, |
| 44 | + { |
| 45 | + ...base, |
| 46 | + entry: { |
| 47 | + 'svelte-eslint-parser': resolve('./svelte-eslint-parser.js') |
| 48 | + }, |
| 49 | + externals: { |
| 50 | + 'svelte/compiler': '$$inject_svelte_compiler$$', |
| 51 | + lodash: '$$inject_lodash$$', |
| 52 | + espree: '$$inject_espree$$', |
| 53 | + 'eslint-scope': '$$inject_eslint_scope$$' |
| 54 | + }, |
| 55 | + plugins: [ |
| 56 | + new WrapperPlugin({ |
| 57 | + test: /svelte-eslint-parser\.js/, |
| 58 | + header: ` |
| 59 | + import * as $$inject_svelte_compiler$$ from 'svelte/compiler'; |
| 60 | + import $$inject_lodash$$ from 'lodash'; |
| 61 | + import $$inject_espree$$ from 'espree'; |
| 62 | + import $$inject_eslint_scope$$ from 'eslint-scope'; |
| 63 | + ` |
| 64 | + }) |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + ...base, |
| 69 | + entry: { |
| 70 | + 'eslint-plugin-svelte3': resolve('./eslint-plugin-svelte3.js') |
| 71 | + }, |
| 72 | + module: { |
| 73 | + rules: [ |
| 74 | + { |
| 75 | + test: /node_modules\/eslint-plugin-svelte3\/index\.js$/u, |
| 76 | + loader: 'string-replace-loader', |
| 77 | + options: { |
| 78 | + search: 'Object\\.keys\\(__require\\.cache\\)', |
| 79 | + replace: (original) => `[] /* ${original} */`, |
| 80 | + flags: '' |
| 81 | + } |
| 82 | + }, |
| 83 | + { |
| 84 | + test: /node_modules\/eslint-plugin-svelte3\/index\.js$/u, |
| 85 | + loader: 'string-replace-loader', |
| 86 | + options: { |
| 87 | + search: 'require\\(linter_path\\)', |
| 88 | + replace: (original) => `{Linter:require('eslint4b')}; // ${original}`, |
| 89 | + flags: '' |
| 90 | + } |
| 91 | + }, |
| 92 | + { |
| 93 | + test: /node_modules\/eslint-plugin-svelte3\/index\.js$/u, |
| 94 | + loader: 'string-replace-loader', |
| 95 | + options: { |
| 96 | + search: "throw new Error\\('Could not find ESLint Linter in require cache'\\);", |
| 97 | + replace: (original) => ` // ${original}`, |
| 98 | + flags: '' |
| 99 | + } |
| 100 | + } |
| 101 | + ] |
| 102 | + }, |
| 103 | + externals: { |
| 104 | + 'svelte/compiler': '$$inject_svelte_compiler$$', |
| 105 | + eslint4b: '$$inject_eslint4b$$' |
| 106 | + }, |
| 107 | + plugins: [ |
| 108 | + new WrapperPlugin({ |
| 109 | + test: /eslint-plugin-svelte3\.js/, |
| 110 | + header: ` |
| 111 | + import * as $$inject_svelte_compiler$$ from 'svelte/compiler'; |
| 112 | + import $$inject_eslint4b$$ from 'eslint4b'; |
| 113 | + ` |
| 114 | + }) |
| 115 | + ] |
| 116 | + }, |
| 117 | + { |
| 118 | + ...base, |
| 119 | + entry: { |
| 120 | + lodash: resolve('./lodash.js') |
| 121 | + } |
| 122 | + } |
| 123 | +]; |
0 commit comments