TrySound / rollup-plugin-string

Converts text files to modules
MIT License
85 stars 13 forks source link

How to import text from inside external modules? #20

Closed ghost closed 5 years ago

ghost commented 5 years ago

I have a package crmish in node_modules with such lines:

// db.js
import ADD_CLIENT from '../sql/add_client.sql';

I import db.js file into another package. And rollup-plugin-string can't transform *.sql files to strings. How to fix it?

Error:

[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript) ../../node_modules/crmish/sql/add_client.sql (1:7) 1: INSERT INTO clients(phone, name, born_date, city) ^ 2: VALUES ($1, $2, $3, $4); Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)

Rollup config:

import nodeResolve from 'rollup-plugin-node-resolve';
import { string } from 'rollup-plugin-string';

export default {
  input: './src/index.ts',

  output: {
    file: './index.js',
    format: 'cjs',
  },

  plugins: [

    string({
      include: '**/*.sql',
    }),

    nodeResolve({
      sourceMap: false,
    }),
  ],
}
ghost commented 5 years ago

It seems that for this i need to transform the *.sql files received from the rollup-plugin-node-resolve. Is it possible? Moving plugin-node-resolve above plugin-string did not help

ghost commented 5 years ago

Self-closing https://github.com/rollup/rollup-pluginutils/issues/39

    string({
      include: /\.sql$/i,
    }),