-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c11ae7
commit 9f094c7
Showing
11 changed files
with
99 additions
and
85 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
dist | ||
node_modules | ||
/index.* | ||
package-lock.json | ||
*.log* | ||
*.result.css | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,28 @@ | ||
import babel from 'rollup-plugin-babel'; | ||
import pkg from './package.json' | ||
|
||
export default { | ||
input: 'src/index.js', | ||
output: [ | ||
{ file: 'index.cjs.js', format: 'cjs', sourcemap: true, strict: false }, | ||
{ file: 'index.esm.mjs', format: 'esm', sourcemap: true, strict: false } | ||
], | ||
plugins: [ | ||
patchBabelPluginSyntaxImportMeta(), | ||
babel({ | ||
plugins: [ | ||
['@babel/plugin-syntax-import-meta'] | ||
], | ||
presets: [ | ||
['@babel/preset-env', { modules: false, targets: { node: 8 } }] | ||
] | ||
}) | ||
] | ||
}; | ||
...pkg.rollup, | ||
plugins: [patchBabelPluginSyntaxImportMeta(), ...pkg.rollup.plugins.map(plugin => require(plugin)())], | ||
onwarn(warning, warn) { | ||
if (warning.code !== 'UNRESOLVED_IMPORT') warn(warning) | ||
} | ||
} | ||
|
||
function patchBabelPluginSyntaxImportMeta () { | ||
return { | ||
name: 'patch-babel-plugin-syntax-import-meta', | ||
renderChunk (code, chunk, options) { | ||
const currentUrlMatch = /var url = require\('url'\);([\W\w]+)const currentURL[^\n]+\nconst currentFilename[^\n]+/; | ||
const currentUrlMatch = /var url = require\('url'\);([\W\w]+)const currentURL[^\n]+\n(const currentFilename)[^\n]+/ | ||
|
||
const shouldTransformImportMeta = options.format === 'cjs' && currentUrlMatch.test(code); | ||
const shouldTransformImportMeta = options.format === 'cjs' && currentUrlMatch.test(code) | ||
|
||
if (shouldTransformImportMeta) { | ||
const updatedCode = code.replace(currentUrlMatch, '$1const currentFilename = __filename;'); | ||
const updatedCode = code.replace(currentUrlMatch, '$1$2 = __filename;') | ||
|
||
return updatedCode; | ||
return updatedCode | ||
} | ||
|
||
return null; | ||
return null | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ os: | |
- osx | ||
|
||
node_js: | ||
- 8 | ||
- 10 | ||
|
||
install: | ||
- npm install --ignore-scripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.